async runtime based on a pluggable dispatcher
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Reynard User 572a8d6852 Initial commit
Signed-off-by: Reynard User <kade@sly.so>
2026-03-31 14:15:34 +02:00
src Initial commit 2026-03-31 14:15:34 +02:00
.gitignore Initial commit 2026-03-31 14:15:34 +02:00
Cargo.toml Initial commit 2026-03-31 14:15:34 +02:00
LICENSE Initial commit 2026-03-31 14:15:34 +02:00
README.md Initial commit 2026-03-31 14:15:34 +02:00

Async Dispatcher

crates.io version docs CI

This crate allows async libraries to spawn tasks and set timers without being tied to a particular async runtime.

The core of this need comes from wanting to be able to use the native OS scheduler, as written about in Zed Decoded: Async Rust.

Libraries can spawn in a generic way:

use async_dispatcher::{spawn, sleep};

pub async my_library_function() {
    let task = spawn(async {
        sleep(Duration::from_secs(1)).await;
        println!("in a spawned task!");
    });

    // ...
}

Applications using those libraries can control how that work is dispatched by implementing the Dispatcher trait:

use async_dispatcher::{set_dispatcher, Dispatcher, Runnable};

struct MyAppDispatcher;

impl Dispatcher for MyAppDispatcher {
    fn dispatch(&self, runnable: Runnable) {
        // ...
    }

    fn dispatch_after(&self, duration: Duration, runnable: Runnable) {
        // ...
    }
}

fn main() {
    set_dispatcher(MyAppDispatcher);

    async_dispatcher::block_on(async move {
        my_library_function().await;
    });
}