A Rust async runtime abstraction library.
Provides a unified Runtime type and traits such as Executor, Reactor, and
AsyncToSocketAddrs that abstract over Tokio, smol, and async-global-executor.
Features enable implementations and may be combined. Applications choose a
runtime when constructing Runtime; library crates can use generic trait
bounds to remain runtime-agnostic.
Feature flags
| Flag | Notes |
|---|---|
tokio (default) |
Tokio runtime |
smol |
smol executor |
async-global-executor |
Executor; combine with async-io for AGERuntime |
async-io |
async-io reactor (required by smol) |
hickory-dns |
Hickory DNS resolver (tokio only) |
NoopRuntime is always available without a feature flag.
An owned Tokio runtime uses nonblocking shutdown when its final owner is dropped while a Tokio
handle is current. This includes a plain Handle::enter() scope, so spawn_blocking work can
continue after the drop returns. Await work that must finish before dropping the final owner. On a
plain thread, leave the Handle::enter() scope first or call shutdown_blocking() to wait. The
method returns the runtime if another clone still owns it or it is called from a Tokio task,
including a spawn_blocking task. Call it from an ordinary thread, not a runtime worker or an
active async executor.
Example
use ;
use ;
async
async
async
Note that the io::Result above is the task's own output: awaiting a task
leaves no room to report that the task itself failed, so a task which panicked
resumes its panic in the awaiting task, and awaiting one which was canceled, or
whose runtime went away, panics too.