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.
They detach on drop by default. Use JoinHandle::cancel_on_drop() to
request cancellation on drop instead.
Use spawn_sendable() to spawn a local future whose Send output can be
awaited on another thread through a SendableJoinHandle. Dropping that
handle detaches the task by default; use SendableJoinHandle::cancel() or
SendableJoinHandle::cancel_on_drop() to request cancellation.
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 a join error. 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. Both the submitted future
and its output must be Send:
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
The tokio and compio features are mutually exclusive. The rt module
always exposes the native scheduler, including Runtime and
RuntimeBuilder, independently of which adapter supplies the
crate-level spawning functions and Handle.
A Runner supplies the event loop used by SystemRunner and arbiter
threads. Building a system only stores its configuration; execution begins
when the returned system runner is driven.
Native event-loop integrations implement Driver and use PollResult
from Runtime::poll to decide whether to wait, poll again, or stop.
Runtime, arbiter, and blocking pool metric types are grouped in metrics.
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::Runtime;pub use self::rt::RuntimeBuilder;pub use self::rt::Handle;pub use self::rt::JoinError;pub use self::rt::JoinHandle;pub use self::rt::RemoteJoinHandle;pub use self::rt::now;pub use self::rt::spawn;pub use self::rt::spawn_detached;
Modules§
- metrics
- Runtime, arbiter, and blocking thread pool metrics.
- rt
- Native single-threaded runtime, task spawning, handles, and clock access.
- signals
- Process-signal subscriptions and optional application-panic notifications.
Macros§
- syscall
- Executes a Unix system call and converts a
-1result to the last I/O error.
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.
- Id
- Identifier assigned to a
SystemorArbiter. - Local
Waker - An owned wake handle that can only be used on the thread that acquired it.
- Sendable
Join Handle - A sendable task handle returned by
spawn_sendable(). - 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§
- Driver
Type - Operating-system I/O mechanism used by a driver.
- Poll
Result - Outcome of one call to
Runtime::poll.
Traits§
- Driver
- Drives I/O events and scheduled tasks for the native
Runtime. - Notify
- Wakes a runtime driver, retaining the wakeup if it has not blocked yet.
- Runner
- Creates and drives an event loop for a system or arbiter thread.
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.
- spawn_
sendable - Spawns a local future and returns a
SendableJoinHandlefor its result. - task_
callbacks ⚠ - Installs process-wide callbacks for instrumenting spawned tasks.
- task_
opt_ ⚠callbacks - Attempts to install process-wide task callbacks.
- with_
item - Provides access to a value in the current arbiter’s thread-local storage.
Type Aliases§
- Block
Future - A boxed, pinned future passed to a
Runner.