Trait governor::state::direct::StreamRateLimitExt

source ·
pub trait StreamRateLimitExt<'a>: Stream {
    // Required methods
    fn ratelimit_stream<D: DirectStateStore, C, MW: RateLimitingMiddleware<C::Instant>>(
        self,
        limiter: &'a RateLimiter<NotKeyed, D, C, MW>,
    ) -> RatelimitedStream<'a, Self, D, C, MW>
       where Self: Sized,
             C: ReasonablyRealtime + Clock;
    fn ratelimit_stream_with_jitter<D: DirectStateStore, C, MW: RateLimitingMiddleware<C::Instant>>(
        self,
        limiter: &'a RateLimiter<NotKeyed, D, C, MW>,
        jitter: Jitter,
    ) -> RatelimitedStream<'a, Self, D, C, MW>
       where Self: Sized,
             C: ReasonablyRealtime + Clock;
}
Expand description

Allows converting a futures::Stream combinator into a rate-limited stream.

Required Methods§

source

fn ratelimit_stream<D: DirectStateStore, C, MW: RateLimitingMiddleware<C::Instant>>( self, limiter: &'a RateLimiter<NotKeyed, D, C, MW>, ) -> RatelimitedStream<'a, Self, D, C, MW>
where Self: Sized, C: ReasonablyRealtime + Clock,

Limits the rate at which the stream produces items.

Note that this combinator limits the rate at which it yields items, not necessarily the rate at which the underlying stream is polled. The combinator will buffer at most one item in order to adhere to the given limiter. I.e. if it already has an item buffered and needs to wait it will not poll the underlying stream.

source

fn ratelimit_stream_with_jitter<D: DirectStateStore, C, MW: RateLimitingMiddleware<C::Instant>>( self, limiter: &'a RateLimiter<NotKeyed, D, C, MW>, jitter: Jitter, ) -> RatelimitedStream<'a, Self, D, C, MW>
where Self: Sized, C: ReasonablyRealtime + Clock,

Limits the rate at which the stream produces items, with a randomized wait period.

Note that this combinator limits the rate at which it yields items, not necessarily the rate at which the underlying stream is polled. The combinator will buffer at most one item in order to adhere to the given limiter. I.e. if it already has an item buffered and needs to wait it will not poll the underlying stream.

Implementors§

source§

impl<'a, S: Stream> StreamRateLimitExt<'a> for S