Other Classes

The following classes are available globally.

  • A PromiseKit Dispatcher that dispatches X closures every Y seconds, on average.

    This implementation is O(1) in both space and time, but it uses approximate time accounting. Over the long term, the rate converges to a rate of X/Y, but the transient burst rate will be up to 2X/Y in some situations.

    For a completely accurate rate limiter that dispatches as rapidly as possible, see StrictRateLimitedDispatcher. That implementation requires additional storage.

    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.

    100% thread safe.

    Declaration

    Swift

    public class RateLimitedDispatcher : 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.

    Declaration

    Swift

    public class StrictRateLimitedDispatcher : RateLimitedDispatcherBase