Skip to main content

Module runtime

Module runtime 

Source
Expand description

NodeRuntime — the async runtime a node’s session lives on.

Blueprint §9.1 shows a node whose main is an ordinary synchronous function, and also promises recv_async(). Both have to work, from the same crate::Node, without the author choosing a colour up front. This module is the one place that reconciles them.

§Three situations, three behaviours

Where Node::init… is calledRuntimeBlocking calls
An ordinary fn mainA two-worker multi-thread runtime this node ownsWork
Inside #[tokio::main] / a multi-thread runtimeThe caller’sWork, through tokio::task::block_in_place
Inside a current-thread runtime (#[tokio::test])The caller’sRefused with NodeError::BlockingInAsync

The third row is the interesting one. A current-thread runtime has exactly one thread; blocking it is not slow, it is a deadlock — the task that would deliver the awaited value can never run. Returning a typed error that names the _async twin to call instead is the only honest answer, and it turns a hang into a compile-cycle-length fix.

§Examples

use astrs_node_api::runtime::NodeRuntime;

let runtime = NodeRuntime::acquire()?;
assert!(runtime.is_owned(), "no runtime was running, so one was built");
assert!(runtime.can_block());

Structs§

OwnedRuntime
A tokio runtime owned by a node, shut down without blocking.

Enums§

NodeRuntime
The runtime a node’s background tasks run on.

Constants§

OWNED_WORKER_THREADS
The number of worker threads an owned node runtime starts with.