3 个版本
0.1.2 | 2019年2月6日 |
---|---|
0.1.1 | 2019年1月28日 |
0.1.0 | 2018年7月30日 |
#13 in #oneshot
每月265次下载
用于 15 个 crate
8KB
99 代码行
fibers_global
fibers 的全局执行器。
此包提供全局 ThreadPoolExecutor
,可以在程序的任何地方启动/执行 fibers。
这对于编写使用 fibers
的测试或示例代码很有用。
示例
use fibers::sync::oneshot;
use futures::{lazy, Future};
// Spawns two auxiliary fibers.
let (tx0, rx0) = oneshot::channel();
let (tx1, rx1) = oneshot::channel();
fibers_global::spawn(lazy(move || {
let _ = tx0.send(1);
Ok(())
}));
fibers_global::spawn(lazy(move || {
let _ = tx1.send(2);
Ok(())
}));
// Executes a calculation that depends on the above fibers.
let result = fibers_global::execute(rx0.join(rx1).map(|(v0, v1)| v0 + v1));
assert_eq!(result.ok(), Some(3));
依赖项
~1–1.2MB
~20K SLoC