1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//! Global tokio runtime — singleton for async scheduling.
//!
//! **Rust-internal.** No Python counterpart (Python's asyncio loop is per-thread).
//!
//! Rationale for a pinned singleton:
//! - `spawn_blocking` for `bound="cpu"` ops (no Python GIL in Rust, but keeps
//! long-running work off tokio worker threads).
//! - `tokio::spawn` for `bound="io"` ops (HTTP, LLM streaming).
//! - Persistent runtime preserves connection pools, DNS cache, thread affinity
//! across many `Operon::run()` calls in long-lived binaries.
use Future;
use OnceLock;
use Runtime;
static TOKIO_RT: = new;
/// Get or create the global tokio runtime.
pub
/// Block on an async future from any context.
///
/// - Inside a tokio runtime (e.g. `spawn_blocking`): uses `Handle::block_on()`.
/// - Outside tokio (e.g. main thread in a sync call): uses the singleton.
///
/// Avoids the "Cannot start a runtime from within a runtime" panic.
pub