#future #send #spawn #task-execution #tokio-task

side-futures

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

3 releases

0.1.2 Jun 12, 2021
0.1.1 Mar 23, 2020
0.1.0 Mar 22, 2020

#646 in Asynchronous

Download history 3/week @ 2024-01-05 2/week @ 2024-01-12 1/week @ 2024-01-19 17/week @ 2024-02-16 44/week @ 2024-02-23 23/week @ 2024-03-01 3/week @ 2024-03-08 70/week @ 2024-03-29 27/week @ 2024-04-05 6/week @ 2024-04-12

103 downloads per month

0BSD license

9KB
113 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