| Crates.io | async-dispatch |
| lib.rs | async-dispatch |
| version | 0.3.0 |
| created_at | 2026-01-14 19:56:27.538327+00 |
| updated_at | 2026-01-15 19:59:12.66385+00 |
| description | Async task dispatch via Grand Central Dispatch |
| homepage | |
| repository | https://github.com/dgrijalva/async-dispatch |
| max_upload_size | |
| id | 2043617 |
| size | 38,861 |
Async task dispatch via Grand Central Dispatch (GCD) for Apple platforms.
Instead of managing your own async runtime (like tokio), this crate hands off task scheduling to the operating system's native dispatch queues. You spawn futures; GCD handles the rest.
API docs are hosted on GitHub Pages. Since this crate only builds on Apple platforms, docs.rs cannot generate documentation for it.
use async_dispatch::{spawn, spawn_on_main, spawn_after, sleep, JoinError};
use std::time::Duration;
// Spawn on a background queue and await the result
spawn(async {
let task = spawn(async {
expensive_computation().await
});
// Await returns Result<T, JoinError>
let result = task.await.unwrap();
});
// Spawn on the main thread (for UI work)
spawn_on_main(async {
update_ui()
});
// Spawn after a delay
spawn_after(Duration::from_secs(5), async {
delayed_work().await
});
// Sleep within an async context
spawn(async {
do_something();
sleep(Duration::from_secs(1)).await;
do_something_else();
});
task.await - wait for completion, returns Result<T, JoinError>task.abort() - cancel the task; awaiting returns Err(JoinError::Aborted)JoinHandle)The crate uses async-task to convert Rust futures into raw function pointers that can be passed to GCD's dispatch_async_f. When GCD executes the function, it polls the future. If the future yields, subsequent wakeups are dispatched back to GCD.
There is no runtime to start or stop. GCD manages thread pools and scheduling.
block_on for synchronously waiting on futures. (use futures::block_on)This approach is based on the dispatcher implementation in Zed's gpui crate, which uses GCD for async task scheduling on macOS. The gpui crate is licensed under Apache-2.0.