Skip to main content

Module runtime

Module runtime 

Source
Expand description

Tokio runtime singleton shared across the process.

Exactly one multi-threaded tokio::runtime::Runtime is created lazily on first call to shared_runtime. All document actors spawn onto it; sync callers (the TUI input loop, tests) bridge into async via block_on which forwards to [tokio::runtime::Handle::block_on].

Why a singleton:

  • The runtime owns its own threadpool. Spawning per-test or per-App runtimes is wasteful and serialises tests poorly.
  • All actor-bound code paths share the same scheduler; cross- actor interactions (post-Phase-7 plugin host invoking the document actor) work without extra plumbing.
  • Dropping a Runtime blocks until its tasks finish; a global one stays alive for the process lifetime.

Why isolation across tests still works: each crate::spawn_document call creates its own actor task with its own mailbox. Tests don’t share state at the actor level even though they share the runtime.

Functions§

block_on
Sync-to-async bridge. Forwards to the shared multi-thread runtime’s block_on. Used by the TUI input loop and by App methods that need to wait on a crate::Pending from outside an async context.
lsp_runtime
Phase 5.5.LSP.1: shared LSP runtime accessor. Multi-threaded, thread-name lattice-lsp. Owns the supervisor actor + per- server actors + read/write loops + diagnostic pumps + the debounced flush task. Survives for the editor’s lifetime.
shared_runtime
Get (or lazily build) the shared runtime’s Handle. Cheap to call repeatedly; the underlying Runtime is built once and stays alive for the process lifetime.
spawn_blocking_on_lsp_runtime
IN.8b: the blocking sibling of spawn_on_lsp_runtime, for work that is genuinely synchronous rather than merely off-thread — spawning a formatter and waiting on its pipes.
spawn_on_lsp_runtime
Phase 5.5.LSP.1: spawn a fire-and-forget future on the shared LSP runtime. Used by the App’s + host’s per-feature LSP dispatchers so the request awaits the actor’s response off the main UI thread; the result flows back through a per- feature mpsc channel that the App drains before each draw.
spawn_task
Fire-and-forget spawn onto the shared runtime. The future runs on a tokio worker thread; the returned JoinHandle is detached (the caller doesn’t await). Used by the mode dispatcher (M-async.2): activation validation runs synchronously on the App thread, then the lifecycle future is spawn_task’d so the App thread doesn’t block on the future’s .await points.