StrictRateLimitedDispatcher

public final class StrictRateLimitedDispatcher : RateLimitedDispatcherBase

A PromiseKit Dispatcher that dispatches no more than X closures every Y seconds. This is a sliding window, so executions occur as rapidly as possible without exceeding X in any Y-second period.

This version implements perfectly accurate timing, so it must (temporarily) track up to X previous execution times and is thus O(X) in space.

For a “pretty good” approach to rate limiting that does not consume additional storage, see RateLimitedDispatcher.

Executions are paced by start time, not by completion, so it’s possible to end up with more than X closures running concurrently in some circumstances.

There is no guarantee that you will reach a given dispatch rate. There are not an infinite number of threads available, and GCD scheduling has limited accuracy. The only guarantee is that dispatching will never exceed the requested rate.

100% thread safe.

  • A PromiseKit Dispatcher that dispatches no more than X executions every Y seconds. This is a sliding window, so executions occur as rapidly as possible without exceeding X in any Y-second period. O(X) in space.

    For a “pretty good” approach to rate limiting that does not consume additional storage, see RateLimitedDispatcher.

    Declaration

    Swift

    override public init(maxDispatches: Int, perInterval interval: TimeInterval, queue: Dispatcher = DispatchQueue.global())

    Parameters

    maxDispatches

    The number of executions that may be dispatched within a given interval.

    perInterval

    The length of the reference interval, in seconds.

    queue

    The DispatchQueue or Dispatcher on which to perform executions. May be serial or concurrent.

  • Undocumented

    Declaration

    Swift

    public convenience init(maxDispatches: Int, perInterval interval: TimeInterval, queue: DispatchQueue)