#pubsub #futures #concurrency


Pubsub and related streams for Rust futures

9 releases (breaking)

0.7.0 Nov 20, 2021
0.6.0 Feb 8, 2021
0.5.0 Jan 31, 2021
0.4.0 Dec 29, 2019
0.1.1 Aug 7, 2018

#79 in Concurrency

Download history 254/week @ 2022-04-21 119/week @ 2022-04-28 105/week @ 2022-05-05 196/week @ 2022-05-12 169/week @ 2022-05-19 178/week @ 2022-05-26 215/week @ 2022-06-02 130/week @ 2022-06-09 181/week @ 2022-06-16 144/week @ 2022-06-23 176/week @ 2022-06-30 167/week @ 2022-07-07 162/week @ 2022-07-14 229/week @ 2022-07-21 147/week @ 2022-07-28 182/week @ 2022-08-04

769 downloads per month
Used in 5 crates (3 directly)



flo_stream = "0.7"


flo_stream is a crate providing some extra utilities for streams in Rust's futures library. The primary new feature it provides is a "pubsub" mechanism - a way to subscribe to updates sent to a futures Sink. This differs from the Sender/Receiver mechanism provided in the main futures library in two key ways: it's possible to have multiple receivers, and messages sent when there is no subscriber connected will be ignored.


The sink type provided is Publisher. You can create one with let publisher = Publisher::new(10). This implements the Sink trait so can be used in a very similar way to send messages. The number passed in is the maximum number of waiting messages allowed for any given subscriber.

A subscription can be created using let subscription = publisher.subscribe(). Any messages sent to the sink after this is called is relayed to all subscriptions. A subscription is a Stream so can interact with other parts of the futures library in the usual way.

Here's a full worked example with a single subscriber:

let mut publisher       = Publisher::new(10);
let mut subscriber      = publisher.subscribe();

executor::block_on(async {

    assert!(subscriber.next().await == Some(1));
    assert!(subscriber.next().await == Some(2));
    assert!(subscriber.next().await == Some(3));

It's also possible to call subscriber.clone() to create a new subscription from an existing one without needing to keep a reference to the publisher. This can be used to reduce the amount of effort needed in passing objects around, and to hide implementation details from the caller.


~18K SLoC