#future #send #spawn

side-futures

Send future for execution on the runtime that may be in a different thread

2 releases

0.1.1 Mar 23, 2020
0.1.0 Mar 22, 2020

#369 in Asynchronous

Download history 10/week @ 2020-11-05 14/week @ 2020-11-12 7/week @ 2020-11-19 22/week @ 2020-11-26 11/week @ 2020-12-03 9/week @ 2020-12-10 3/week @ 2020-12-17 14/week @ 2020-12-24 9/week @ 2020-12-31 7/week @ 2021-01-07 10/week @ 2021-01-14 21/week @ 2021-01-21 14/week @ 2021-01-28 19/week @ 2021-02-04 34/week @ 2021-02-11 29/week @ 2021-02-18

64 downloads per month

0BSD license

8KB
102 lines

Side futures

Build Status Crates.io Docs License

This crate provides an ability to send future for execution on the runtime that may be in a different thread. Typical use case is heavily threaded application where there are synchronous callbacks, but some asynchronous tasks also need to be executed.

Example

To get started, add the following to Cargo.toml.

side-futures = "0.1.0"

Typical usage with Tokio runtime:

use tokio::task;

#[tokio::main]
async fn main() {
    let (sender, receiver) = side_futures::create();
    task::spawn(receiver.run_receiver(task::spawn));
    sender
        .send_future(async {
            // Do stuff
        })
        .unwrap();
}

Typical usage with Actix runtime:

#[actix_rt::main]
async fn main() {
    let (sender, receiver) = side_futures::create();
    actix_rt::spawn(receiver.run_receiver(actix_rt::spawn));
    sender
        .send_future(async {
            // Do stuff
        })
        .unwrap();
}

Contribution

Feel free to create issues and send pull requests, they are highly appreciated!

License

Zero-Clause BSD

https://opensource.org/licenses/0BSD

https://tldrlegal.com/license/bsd-0-clause-license

Dependencies

~1MB
~16K SLoC