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 called | Runtime | Blocking calls |
|---|---|---|
An ordinary fn main | A two-worker multi-thread runtime this node owns | Work |
Inside #[tokio::main] / a multi-thread runtime | The caller’s | Work, through tokio::task::block_in_place |
Inside a current-thread runtime (#[tokio::test]) | The caller’s | Refused 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§
- Owned
Runtime - A tokio runtime owned by a node, shut down without blocking.
Enums§
- Node
Runtime - The runtime a node’s background tasks run on.
Constants§
- OWNED_
WORKER_ THREADS - The number of worker threads an owned node runtime starts with.