Skip to main content

Crate nexus_async_rt

Crate nexus_async_rt 

Source
Expand description

Single-threaded async runtime.

Two spawn strategies:

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§

channel
Async channels for task communication.
net
Async network primitives.

Structs§

Backoff
Exponential backoff with optional jitter and deadline.
BackoffBuilder
Builder for Backoff.
ByteSlab
Growable byte slab. Mirrors crate::unbounded::Slab but stores heterogeneous types in fixed-size byte slots.
CancellationToken
A token for cooperative cancellation.
DropGuard
A guard that cancels a CancellationToken when dropped.
Elapsed
Error returned when a Timeout expires.
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
Copy handle for IO operations from async tasks.
JoinHandle
Handle to a spawned task. Await to get the result.
QuiesceTimeout
Returned by Runtime::shutdown_quiesce when the timeout elapses before the executor reaches a quiesced state.
Runtime
Single-threaded async runtime.
RuntimeBuilder
Builder for configuring a Runtime.
ShutdownHandle
Shared shutdown flag.
ShutdownSignal
Future that resolves when shutdown is triggered.
ShutdownStats
Counters for abnormal-shutdown paths. Snapshot returned by Runtime::shutdown_stats.
ShutdownStatsAtomics
Atomic counters backing ShutdownStats. Written by Executor, readable via the handle returned by Runtime::shutdown_stats.
SlabClaim
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, or Err(Elapsed) if the deadline fires first.
TimerHandle
Copy handle for scheduling timers from async tasks.
WorldCtx
Copy handle for synchronous World access from async tasks.
YieldNow
Future that yields once, then completes.

Enums§

MissedTickBehavior
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 the storage field.

Functions§

after
Run a future no earlier than deadline.
after_delay
Run a future after duration elapses.
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 every period.
sleep
Create a Sleep future that completes after duration.
sleep_until
Create a Sleep future that completes at deadline.
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 None if the slab is full.
yield_now
Cooperatively yield the current task.