Expand description
Single-threaded async runtime.
Two spawn strategies:
spawn_boxed()— Box-allocated. Default. No setup needed.spawn_slab()— Slab-allocated. Pre-allocated, zero-alloc hot path. Requires slab configured viaRuntimeBuilder::slab_unboundedorRuntimeBuilder::slab_bounded.
ⓘ
use nexus_async_rt::*;
use nexus_slab::byte::unbounded::Slab;
use nexus_rt::WorldBuilder;
let mut world = WorldBuilder::new().build();
// Simple — Box-allocated tasks, no slab setup
let mut rt = Runtime::new(&mut world);
rt.block_on(async {
spawn_boxed(async { /* Box-allocated */ });
});
// Power user — with slab for hot-path tasks
// SAFETY: single-threaded runtime.
let slab = unsafe { Slab::<256>::with_chunk_capacity(64) };
let mut rt = Runtime::builder(&mut world)
.slab_unbounded(slab)
.build();
rt.block_on(async {
spawn_boxed(async { /* Box-allocated, long-lived */ });
spawn_slab(async { /* slab-allocated, hot path */ });
});Re-exports§
pub use net::AsyncRead;pub use net::AsyncWrite;pub use net::OwnedReadHalf;pub use net::OwnedWriteHalf;pub use net::ReadHalf;pub use net::TcpListener;pub use net::TcpSocket;pub use net::TcpStream;pub use net::UdpSocket;pub use net::WriteHalf;
Modules§
Structs§
- Backoff
- Exponential backoff with optional jitter and deadline.
- Backoff
Builder - Builder for
Backoff. - Byte
Slab - Growable byte slab. Mirrors
crate::unbounded::Slabbut stores heterogeneous types in fixed-size byte slots. - Cancellation
Token - A token for cooperative cancellation.
- Drop
Guard - A guard that cancels a
CancellationTokenwhen dropped. - Elapsed
- Error returned when a
Timeoutexpires. - Executor
- Single-threaded async executor.
- Exhausted
- Retries exhausted — either max retries reached or deadline passed.
- Interval
- Periodic timer that ticks at a fixed interval.
- IoHandle
Copyhandle for IO operations from async tasks.- Join
Handle - Handle to a spawned task. Await to get the result.
- Quiesce
Timeout - Returned by
Runtime::shutdown_quiescewhen the timeout elapses before the executor reaches a quiesced state. - Runtime
- Single-threaded async runtime.
- Runtime
Builder - Builder for configuring a
Runtime. - Shutdown
Handle - Shared shutdown flag.
- Shutdown
Signal - Future that resolves when shutdown is triggered.
- Shutdown
Stats - Counters for abnormal-shutdown paths. Snapshot returned by
Runtime::shutdown_stats. - Shutdown
Stats Atomics - Atomic counters backing
ShutdownStats. Written byExecutor, readable via the handle returned byRuntime::shutdown_stats. - Slab
Claim - A reserved slab slot for the async runtime.
- Sleep
- Future that completes when a deadline expires.
- Timeout
- Future that completes with
Ok(T)if the inner future finishes before the deadline, orErr(Elapsed)if the deadline fires first. - Timer
Handle Copyhandle for scheduling timers from async tasks.- World
Ctx Copyhandle for synchronousWorldaccess from async tasks.- Yield
Now - Future that yields once, then completes.
Enums§
- Missed
Tick Behavior - Strategy for handling missed interval ticks.
Constants§
- MIN_
SLOT_ SIZE - Recommended minimum slab slot size.
- TASK_
HEADER_ SIZE - Header size in bytes. Must match the layout of
Task<F>before thestoragefield.
Functions§
- after
- Run a future no earlier than
deadline. - after_
delay - Run a future after
durationelapses. - claim_
slab - Reserve a slab slot. Panics if full or no slab configured.
- event_
time - Timestamp taken after the most recent IO poll cycle.
- interval
- Create an interval that ticks at a fixed period.
- interval_
at - Create an interval that starts ticking at
start, then everyperiod. - sleep
- Create a
Sleepfuture that completes afterduration. - sleep_
until - Create a
Sleepfuture that completes atdeadline. - spawn_
boxed - Spawn a Box-allocated task into the current runtime.
- spawn_
slab - Spawn a slab-allocated task into the current runtime.
- timeout
- Wrap a future with a deadline. Returns
Err(Elapsed)if the deadline expires before the future completes. - timeout_
at - Wrap a future with an absolute deadline. Returns
Err(Elapsed)if the deadline passes before the future completes. - try_
claim_ slab - Try to reserve a slab slot. Returns
Noneif the slab is full. - yield_
now - Cooperatively yield the current task.