pub trait StreamExt: Stream {
    fn future_queue<Fut>(self, max_weight: usize) -> FutureQueue<Self>
    where
        Self: Sized + Stream<Item = (usize, Fut)>,
        Fut: Future
, { ... } fn future_queue_grouped<Fut, I, K, Q>(
        self,
        max_global_weight: usize,
        groups: I
    ) -> FutureQueueGrouped<Self, K>
    where
        I: IntoIterator<Item = (K, usize)>,
        K: Eq + Hash + Borrow<Q> + Debug,
        Q: Eq + Hash + Debug,
        Self: Sized + Stream<Item = (usize, Option<Q>, Fut)>,
        Fut: Future
, { ... } }
Expand description

An extension trait for Streams that provides future_queue.

Provided Methods§

An adaptor for creating a queue of pending futures (unordered), where each future has a different weight.

This stream must return values of type (usize, impl Future), where the usize indicates the weight of each future. This adaptor will buffer futures up to weight max_weight, and then return the outputs in the order in which they complete.

The weight may be exceeded if the last future to be queued has a weight greater than max_weight minus the total weight of currently executing futures. However, no further futures will be queued until the total weights of running futures falls below max_weight.

The adaptor will schedule futures in the order they’re returned by the stream, without doing any reordering based on weight.

The weight of a future can be zero, in which case it will not count towards the total weight.

The returned stream will be a stream of each future’s output.

Examples

See the crate documentation for an example.

An adaptor for creating a queue of pending futures, where each future has a different weight and optional group.

This method accepts a maximum global weight, as well as a set of groups of type K. Each group has a defined maximum weight. This stream must return values of type (usize, Option<Q>, impl Future), where K is Borrow<Q>.

This adapter will buffer futures up to weight max_weight. If the optional group is specified for a future, it will also check that the weight of futures in that group does not exceed the specified limit. Any futures that exceed the group’s weight limit will be queued up, but not scheduled until the weight of futures in that group falls below the limit.

The adaptor is as fair as possible under the given constraints: it will schedule futures in the order they’re returned by the stream, without doing any reordering based on weight. When a future from a group completes, queued up futures in this group will be preferentially scheduled before any other futures from the provided stream.

The weight of a future can be zero, in which case it will not count towards the total weight.

The returned stream will be a stream of each future’s output.

Panics

The stream panics if the optional group provided by a stream element isn’t in the set of known groups.

Implementors§