future_pubsub

Crates.iofuture_pubsub
lib.rsfuture_pubsub
version0.1.3
sourcesrc
created_at2017-11-01 00:57:52.750081
updated_at2017-11-01 21:49:11.447291
descriptionA tokio based publish-subscibe channel
homepage
repositoryhttps://github.com/AtsukiTak/future-pubsub
max_upload_size
id37628
size15,146
Atsuki Takahashi (AtsukiTak)

documentation

README

future_pubsub

MIT licensed Apache-2.0 licensed Crates.io

A tokio future based publish-subscribe channel.

Document

For now, this crate provides

  • unsync unbounded publish subscribe channel

  • unsync unbounded cloneable stream

And will provide in future

  • unsync bounded publish subscribe channel

  • sync unbounded publish subscribe channel

  • sync bounded publish subscribe channel

  • unsync bounded cloneable stream

  • sync unbounded cloneable stream

  • sync bounded cloneable stream

How to use

Publish-Subscribe channel

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

use future_pubsub::unsync::unbounded;

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

    tx.send(1).wait().unwrap();

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

Cloneable stream

use future_pubsub::unsync::into_cloneable;

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

    let cloneable = into_cloneable(stream);
    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]);
}
Commit count: 0

cargo fmt