19 releases (8 breaking)
Uses new Rust 2024
new 0.8.0 | Sep 13, 2025 |
---|---|
0.6.5 | Aug 23, 2025 |
#843 in Asynchronous
2,522 downloads per month
Used in tcp-stream
55KB
1.5K
SLoC
Features
- tokio: enable the tokio implementation (default)
- smol: enable the smol implementation
- async-global-executor: enable the async-global-executor implementation
- async-io: enable the async-io reactor implementation
Example
use async_rs::{Runtime, TokioRuntime, traits::*};
use std::{io, time::Duration};
async fn get_a(rt: &TokioRuntime) -> io::Result<u32> {
rt.spawn_blocking(|| Ok(12)).await
}
async fn get_b(rt: &TokioRuntime) -> io::Result<u32> {
rt.spawn(async { Ok(30) }).await
}
async fn tokio_main(rt: &TokioRuntime) -> io::Result<()> {
let a = get_a(rt).await?;
let b = get_b(rt).await?;
rt.sleep(Duration::from_millis(500)).await;
assert_eq!(a + b, 42);
Ok(())
}
fn main() -> io::Result<()> {
let rt = Runtime::tokio()?;
rt.block_on(tokio_main(&rt))
}
Dependencies
~2–35MB
~518K SLoC