Skip to main content

Module rt

Module rt 

Source
Expand description

Native single-threaded runtime, task spawning, handles, and clock access.

This module always uses the native scheduler, regardless of which runtime backend is selected at the crate root. Its spawning functions and handles are re-exported at the crate root when neither tokio nor compio is enabled. The free spawning functions require an active Runtime, not an active System.

A Driver supplies the event loop and interprets the PollResult returned by Runtime::poll. Runtime::block_on installs the native runtime while that driver runs, even when Tokio or Compio is selected:

use ntex_rt::rt;

let runtime = rt::Runtime::new(driver.handle());
runtime.block_on(
    async {
        let task = rt::spawn(async { std::rc::Rc::new(42) });
        assert_eq!(*task.await.unwrap(), 42);
    },
    &driver,
);

Structs§

Handle
A thread-safe handle used to schedule work on a runtime.
JoinError
Error returned by crate::spawn_sendable() when no task output is available.
JoinHandle
A native local task handle. It is neither Send nor Sync.
RemoteJoinHandle
A native task handle returned by crate::rt::Handle::spawn().
Runtime
The native single-threaded task scheduler.
RuntimeBuilder
Builder for Runtime.

Functions§

now
Returns the start of the current runtime turn.
spawn
Spawns a future on the current native runtime and returns its join handle.
spawn_detached
Spawns a future on the current thread without a join handle.