Effect CommunityEC
Effect Community3y ago
22 replies
Tim Smart

Rate Limit Policy

I have the following rate limit policy:

const rateLimitPolicy = pipe(
  Schedule.recurs(5),
  Schedule.whileInput((_: Http.StatusCodeError) => _.status === 429),
  Schedule.passthrough,
  Schedule.addDelay(_ =>
    pipe(
      Option.fromNullable(_.response.headers.get("retry-after")),
      Option.map(_ => Duration.seconds(+_)),
      Option.getOrElse(() => Duration.millis(500)),
    ),
  ),
)


What is the best way to refine another Schedule that has a wider input type to use it?

Lets say, Http.RequestError | Http.StatusCodeError.
Was this page helpful?