#fibers #executor #anywhere #test #future #sync #oneshot

dev fibers_global

fibers 的全局执行器

3 个版本

0.1.2 2019年2月6日
0.1.1 2019年1月28日
0.1.0 2018年7月30日

#13 in #oneshot

Download history 74/week @ 2024-03-11 93/week @ 2024-03-18 131/week @ 2024-03-25 171/week @ 2024-04-01 56/week @ 2024-04-08 67/week @ 2024-04-15 82/week @ 2024-04-22 107/week @ 2024-04-29 68/week @ 2024-05-06 75/week @ 2024-05-13 57/week @ 2024-05-20 56/week @ 2024-05-27 56/week @ 2024-06-03 72/week @ 2024-06-10 70/week @ 2024-06-17 63/week @ 2024-06-24

每月265次下载
用于 15 个 crate

MIT 许可协议

8KB
99 代码行

fibers_global

Documentation Build Status Code Coverage License: MIT

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