4个版本
使用旧的Rust 2015
0.1.3 | 2017年11月1日 |
---|---|
0.1.2 | 2017年11月1日 |
0.1.1 | 2017年11月1日 |
0.1.0 | 2017年11月1日 |
#1932 in 异步
每月 23 次下载
13KB
281 行
future_pubsub
基于tokio未来的发布/订阅通道。
目前,此crate提供
- 非同步无界发布/订阅通道
- 非同步无界可克隆流
未来将提供
- 非同步有界发布/订阅通道
- 同步无界发布/订阅通道
- 同步有界发布/订阅通道
- 非同步有界可克隆流
- 同步无界可克隆流
- 同步有界可克隆流
如何使用
发布/订阅通道
用法几乎与 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));
}
可克隆流
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]);
}
依赖项
~53KB