#async-stream #multiplexer #stream

streamunordered

An efficient async stream multiplexer

15 releases

0.5.3 Sep 9, 2023
0.5.2 Feb 2, 2021
0.5.1 Jan 29, 2020
0.5.0 Nov 27, 2019
0.4.0 Jun 1, 2018

#328 in Asynchronous

Download history 610/week @ 2023-11-03 477/week @ 2023-11-10 845/week @ 2023-11-17 714/week @ 2023-11-24 471/week @ 2023-12-01 408/week @ 2023-12-08 353/week @ 2023-12-15 369/week @ 2023-12-22 319/week @ 2023-12-29 618/week @ 2024-01-05 669/week @ 2024-01-12 701/week @ 2024-01-19 524/week @ 2024-01-26 459/week @ 2024-02-02 536/week @ 2024-02-09 739/week @ 2024-02-16

2,373 downloads per month
Used in 8 crates (6 directly)

MIT/Apache

58KB
785 lines

streamunordered

Crates.io Documentation Build Status

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 Ok(Async::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 Ok(Async::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 Ok(Async::NotReady) 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 or StreamUnordered::get_mut.

Dependencies

~770KB
~14K SLoC