Expand description
Single-threaded asynchronous runtime infrastructure for ntex.
A System owns the runtime configuration and coordinates one or more
Arbiter execution threads. Each arbiter runs local futures on its own
thread, allowing tasks to use types that are not Send.
Use System::build() to configure a system, spawn() to start a local
task, and spawn_blocking() for blocking work.
Local JoinHandles are neither Send nor Sync, even for Send outputs:
fn send<T: Send>() {}
send::<ntex_rt::JoinHandle<usize>>();fn sync<T: Sync>() {}
sync::<ntex_rt::JoinHandle<usize>>();Handle::spawn() submits a Send future to the handle’s runtime and
returns a RemoteJoinHandle for the calling thread. On the runtime’s own thread
the task is spawned directly. From other threads the future and later its
Send output share one allocation, which is passed to the runtime thread:
let task = handle.spawn(async { 42 });
assert_eq!(task.await.unwrap(), 42);Dropping the handle detaches the task, RemoteJoinHandle::cancel() cancels it.
A submitted future is polled and dropped on the runtime thread; shutdown or
cancellation before producing a result yields JoinError. No task is
guaranteed to finish. Rejected submissions are never polled and their
futures may be dropped on the submitting thread.
Use Handle::spawn_detached() for fire-and-forget work. Its output need
not be Send and is discarded on the owner.
Remote join handles also remain on their calling thread, even when the submission uses the runtime’s local fast path:
fn send<T: Send>() {}
send::<ntex_rt::RemoteJoinHandle<usize>>();fn sync<T: Sync>() {}
sync::<ntex_rt::RemoteJoinHandle<usize>>();handle.spawn(async { std::rc::Rc::new(42) });LocalWaker owns a thread-confined wake handle. It specializes native
task wakes on their owner thread and preserves standard waker behavior
for other runtimes and wrapped wakers.
Runtime backends are selected with Cargo features:
- no runtime feature uses the native ntex runtime
tokiouses the Tokio-based runtime adaptercompiouses the Compio-based runtime adapter
Re-exports§
pub use self::arbiter::Arbiter;pub use self::arbiter::get_item;pub use self::arbiter::set_item;pub use self::arbiter::with_item;pub use self::rt_default::*;
Modules§
Macros§
- syscall
- Helper macro to execute a system call
Structs§
- Arbiter
- An asynchronous execution environment running on one OS thread.
- Blocking
Error - Error returned when blocking work cannot produce a result.
- Blocking
Result - Future resolving to the result of blocking work.
- Builder
- Builder for an ntex runtime system.
- Histogram
- Snapshot of a duration histogram.
- Id
- Identifier assigned to a running
System. - Latency
Metrics - Snapshot of an arbiter’s scheduling latency.
- Local
Waker - An owned wake handle that can only be used on the thread that acquired it.
- Ping
Record - Pool
Metrics - Snapshot of
ThreadPoolmetrics. - Runtime
- The async runtime for ntex.
- Runtime
Builder - Builder for
Runtime. - System
- Runtime manager for a group of arbiter threads.
- System
Runner - A configured system that has not yet started its event loop.
- Thread
Pool - A thread pool for executing blocking operations.
Enums§
Constants§
- HISTOGRAM_
BUCKETS - Number of
Histogrambuckets.
Traits§
Functions§
- get_
item - Returns a cloned value from the current arbiter’s thread-local storage.
- set_
item - Inserts a value into the current arbiter’s thread-local storage.
- spawn_
blocking - Submits blocking work and returns a future for its result.
- task_
callbacks ⚠ - Safety
- task_
opt_ ⚠callbacks - Safety
- with_
item - Provides access to a value in the current arbiter’s thread-local storage.