Crate streamunordered
source ·Expand description
A stream that efficiently multiplexes multiple streams.
This “combinator” provides the ability to maintain and drive a set of streams to completion, while also providing access to each stream as it yields new elements.
Streams are inserted into this set and their realized values are yielded as they are produced.
This structure is optimized to manage a large number of streams. Streams managed by
StreamUnordered
will only be polled when they generate notifications. This reduces the
required amount of work needed to coordinate large numbers of streams.
When a StreamUnordered
is first created, it does not contain any streams. Calling poll
in
this state will result in Poll::Ready((None)
to be returned. Streams are submitted to the
set using insert
; however, the stream will not be polled at this point. StreamUnordered
will only poll managed streams when StreamUnordered::poll
is called. As such, it is important
to call poll
after inserting new streams.
If StreamUnordered::poll
returns Poll::Ready(None)
this means that the set is
currently not managing any streams. A stream may be submitted to the set at a later time. At
that point, a call to StreamUnordered::poll
will either return the stream’s resolved value
or Poll::Pending
if the stream has not yet completed.
Whenever a value is yielded, the yielding stream’s index is also included. A reference to the
stream that originated the value is obtained by using StreamUnordered::get
,
StreamUnordered::get_mut
, or StreamUnordered::get_pin_mut
.
In normal operation, poll
will yield a StreamYield::Item
when it completes successfully.
This value indicates that an underlying stream (the one indicated by the included index)
produced an item. If an underlying stream yields Poll::Ready(None)
to indicate termination,
a StreamYield::Finished
is returned instead. Note that as soon as a stream returns
StreamYield::Finished
, its token may be reused for new streams that are added.
Structs
- A stream that has yielded all the items it ever will.
- Mutable iterator over all streams in the unordered set.
- Mutable iterator over all streams in the unordered set.
- Mutable iterator over all streams in the unordered set.
- Mutable iterator over all streams in the unordered set.
- Immutable iterator over all streams in the unordered set.
- A handle to an vacant stream slot in a
StreamUnordered
. - A set of streams which may yield items in any order.
Enums
- An event that occurred for a managed stream.