| Crates.io | fibers_global |
| lib.rs | fibers_global |
| version | 0.1.2 |
| created_at | 2018-07-30 13:29:56.845072+00 |
| updated_at | 2019-02-06 16:37:49.3304+00 |
| description | The global executor of fibers |
| homepage | https://github.com/sile/fibers_global |
| repository | https://github.com/sile/fibers_global |
| max_upload_size | |
| id | 76630 |
| size | 9,786 |
The global executor of fibers.
This crate provides the global ThreadPoolExecutor that enables to spawn/execute fibers anywhere in a program.
This is useful for briefly writing test or example code that use 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));