Package: effect
Module: RateLimiter
Constructs a new RateLimiter which will utilize the specified algorithm
to limit requests (defaults to token-bucket).
Notes
RateLimiter can be composed.withCostExample
import { Effect, RateLimiter } from "effect";
import { compose } from "effect/Function"
const program = Effect.scoped(
Effect.gen(function* ($) {
const perMinuteRL = yield* $(RateLimiter.make({ limit: 30, interval: "1 minutes" }))
const perSecondRL = yield* $(RateLimiter.make({ limit: 2, interval: "1 seconds" }))
// This rate limiter respects both the 30 calls per minute
// and the 2 calls per second constraints.
const rateLimit = compose(perMinuteRL, perSecondRL)
// simulate repeated calls
for (let n = 0; n < 100; n++) {
// wrap the effect we want to limit with rateLimit
yield* $(rateLimit(Effect.log("Calling RateLimited Effect")));
}
})
);
Signature
declare const make: (options: RateLimiter.Options) => Effect<RateLimiter, never, Scope>
Since v2.0.0