Skip to main content

Crate ntex_rt

Crate ntex_rt 

Source
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
  • tokio uses the Tokio-based runtime adapter
  • compio uses 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§

rt_default
signals

Macros§

syscall
Helper macro to execute a system call

Structs§

Arbiter
An asynchronous execution environment running on one OS thread.
BlockingError
Error returned when blocking work cannot produce a result.
BlockingResult
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.
LatencyMetrics
Snapshot of an arbiter’s scheduling latency.
LocalWaker
An owned wake handle that can only be used on the thread that acquired it.
PingRecord
PoolMetrics
Snapshot of ThreadPool metrics.
Runtime
The async runtime for ntex.
RuntimeBuilder
Builder for Runtime.
System
Runtime manager for a group of arbiter threads.
SystemRunner
A configured system that has not yet started its event loop.
ThreadPool
A thread pool for executing blocking operations.

Enums§

DriverType
PollResult

Constants§

HISTOGRAM_BUCKETS
Number of Histogram buckets.

Traits§

Driver
Notify
Wakes a runtime driver, retaining the wakeup if it has not blocked yet.
Runner

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.

Type Aliases§

BlockFuture