#async-runtime #dispatcher #task-scheduling #sleep #os-scheduler

async-dispatcher

async runtime based on a pluggable dispatcher

3 releases

0.1.2 May 31, 2024
0.1.1 May 31, 2024
0.1.0 May 31, 2024

#2750 in Asynchronous

Download history 2644/week @ 2025-12-17 1463/week @ 2025-12-24 1838/week @ 2025-12-31 2846/week @ 2026-01-07 2622/week @ 2026-01-14 2896/week @ 2026-01-21 2573/week @ 2026-01-28 3581/week @ 2026-02-04 3368/week @ 2026-02-11 3695/week @ 2026-02-18 3502/week @ 2026-02-25 4280/week @ 2026-03-04 3630/week @ 2026-03-11 3599/week @ 2026-03-18 3350/week @ 2026-03-25 4386/week @ 2026-04-01

15,481 downloads per month
Used in 5 crates (4 directly)

Apache-2.0

8KB
166 lines

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

Dependencies

~445KB