ex-futures 0.4.3

An extension of `futures`


MIT licensed Apache-2.0 licensed Crates.io

An extension of futures.


For now, this crate provides

  • unsync unbounded publish subscribe channel
  • unsync unbounded cloneable stream/sink

And will provide in future

  • unsync bounded publish subscribe channel
  • sync unbounded publish subscribe channel
  • sync bounded publish subscribe channel
  • unsync bounded cloneable stream/sink
  • sync unbounded cloneable stream/sink
  • sync bounded cloneable stream/sink

How to use

Publish-Subscribe channel

An usage is almost same with futures::unsync::mpsc::unbounded.

use ex_futures::unsync::pubsub::unbounded;

fn main() {
    let (tx, rx) = unbounded::<usize>();
    let rx2 = rx.clone();
    let mut rx = rx.wait();
    let mut rx2 = rx.wait();


    assert_eq!(rx.next().unwrap().map(|i| *i), Ok(1));
    assert_eq!(rx2.next().unwrap().map(|i| *i), Ok(1));

Cloneable stream/sink

use ex_futures::StreamExt;

fn main() {
    let stream = gen_inc_stream();;

    let cloneable = stream.unsync_cloneable();
    let cloneable2 = cloneable.clone();

    assert_eq!(cloneable.map(|i| *i).collect().wait().unwrap(), [0, 1, 2, 3]);
    assert_eq!(cloneable2.map(|i| *i).collect().wait().unwrap(), [0, 1, 2, 3]);