RateLimitedDispatcher
public final class RateLimitedDispatcher : RateLimitedDispatcherBase
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.
-
A
PromiseKitDispatcherthat dispatches X executions every Y seconds, on average.This version is O(1) in space and time but uses an approximate algorithm with burst rates up to 2X per Y seconds. For a more accurate implementation, use
StrictRateLimitedDispatcher.Declaration
Swift
override public init(maxDispatches: Int, perInterval interval: TimeInterval, queue: Dispatcher = DispatchQueue.global())Parameters
maxDispatchesThe number of executions that may be dispatched within a given interval.
perIntervalThe length of the reference interval, in seconds.
queueThe 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)
View on GitHub
RateLimitedDispatcher Class Reference