Trait Throttler

Source
pub trait Throttler<T>: Stream<Item = ()> {
    // Required methods
    fn throttle_pending(self: Pin<&mut Self>, cx: &mut Context<'_>);
    fn throttle_ready(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>,
        next_item: Option<&T>,
    );
}
Expand description

Callbacks for throttling a stream

Required Methods§

Source

fn throttle_pending(self: Pin<&mut Self>, cx: &mut Context<'_>)

A new item has been received from the input stream.

After invocation of this method throttle_ready will be called with Some when the current interval has elapsed. The current item that will be yielded may still change until throttle_ready is called.

The cx argument is only provided for consistency and can safely be ignored in most cases. The throttler will be polled immediately after this method returns.

Source

fn throttle_ready( self: Pin<&mut Self>, cx: &mut Context<'_>, next_item: Option<&T>, )

The current interval has elapsed.

Provides the pending item of the throttled input stream that is ready or None if no item has been received from the input stream during the last interval.

Implementors§