pub struct Runtime { /* private fields */ }Expand description
A runtime: worker shards and a blocking pool. Dropping it stops the workers, drops the tasks they still hold, and waits for the threads to exit; then, on the dropping thread, for what the handles those tasks held left behind (the bytes a socket’s write-behind holds, a file’s writes) to land, each for at most a minute, so nothing they accepted is lost.
Implementations§
Source§impl Runtime
impl Runtime
Sourcepub fn enter(&self) -> EnterGuard<'_>
pub fn enter(&self) -> EnterGuard<'_>
Sets this runtime on the calling thread until the guard drops, so the
free functions use it outside block_on.
let runtime = nuclei::Runtime::builder().worker_threads(1).build().unwrap();
let _guard = runtime.enter();
let task = nuclei::spawn(async { 2 + 2 });
assert_eq!(runtime.block_on(task), 4);Sourcepub fn shutdown_background(self)
pub fn shutdown_background(self)
Stops the workers and returns at once: the worker threads drop their tasks and exit on their own, without being waited for, and what the handles of those tasks left behind is delivered on threads of its own.
Source§impl Runtime
impl Runtime
Sourcepub fn stats(&self) -> Stats
pub fn stats(&self) -> Stats
A snapshot of this runtime’s counters: Stats::shards lists its
workers (stopped ones included) by place, and the blocking counts are
its pool’s. The errors of threads that run no shard and the receive
buffers missing are the process’s, as in stats():
they belong to no runtime. The shard of a thread inside this
runtime’s block_on serves every runtime the thread enters, so only
stats() lists it.
Source§impl Runtime
impl Runtime
Sourcepub fn handle(&self) -> RuntimeHandle
pub fn handle(&self) -> RuntimeHandle
A handle to spawn on this runtime from anywhere.
Sourcepub fn block_on<F: Future>(&self, future: F) -> F::Output
pub fn block_on<F: Future>(&self, future: F) -> F::Output
Runs future to its end on the calling thread; see block_on.
Sourcepub fn spawn<F>(&self, future: F) -> Task<F::Output> ⓘ
pub fn spawn<F>(&self, future: F) -> Task<F::Output> ⓘ
Spawns a task on one of the runtime’s shards; see spawn.
Sourcepub fn spawn_blocking<F, T>(&self, f: F) -> Task<T> ⓘ
pub fn spawn_blocking<F, T>(&self, f: F) -> Task<T> ⓘ
Runs f on the runtime’s blocking pool; see spawn_blocking.
Sourcepub fn shutdown_timeout(self, timeout: Duration)
pub fn shutdown_timeout(self, timeout: Duration)
Stops the workers and waits for them up to timeout; workers still
running a task then are left to exit on their own. What the handles
of the tasks dropped left behind gets the rest of timeout to land,
on this thread; what has not by then is given up.