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

dev fibers_global

The global executor of fibers

3 releases

0.1.2 Feb 6, 2019
0.1.1 Jan 28, 2019
0.1.0 Jul 30, 2018

#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 downloads per month
Used in 15 crates

MIT license

8KB
99 lines

fibers_global

Documentation Build Status Code Coverage License: MIT

The global executor of fibers.

Documentation

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.

Examples

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));

Dependencies

~1–1.2MB
~20K SLoC