RateLimiter converts any
futures::stream::Stream into a rate-limited
stream, allowing only a certain number of elements to be polled in a given time interval.
RateLimiter uses the token-bucket algorithm for flow control. RateLimiter acquires a token/permit before polling any element from the underlying stream. If there are no more tokens, it must wait for new tokens to be added back through a periodic refill process.
The token-bucket is in turn implemented using a futures-aware semapahore. The semaphore is initialized with some capacity, and the periodic refill process adds back permits removed during the previous interval.
If fine-grained flow control is desired, the refill interval should be kept small.
Stream for the
Config parameters for a rate-limiter.