Expand description
A shared tokio runtime for running background workers across multiple components.
Components such as the trace exporter can share one runtime instead of each creating their own, reducing thread and resource overhead.
§Choosing a runtime
| Runtime | Target | Threads | Fork-safe | block_on | When to use |
|---|---|---|---|---|---|
ForkSafeRuntime | native | multi | yes — full protocol | yes | Default for native code that may run in a forking process (e.g. Ruby, Python runtimes). |
BasicRuntime | native | multi* | no | yes | Native code where fork() is not a concern; optionally share an existing Arc<tokio::runtime::Runtime> via BasicRuntime::from_handle. |
[LocalRuntime] | wasm32 | single | n/a | no | WebAssembly; spawns via wasm_bindgen_futures::spawn_local. |
* BasicRuntime::new and BasicRuntime::with_worker_threads build a multi-thread runtime;
BasicRuntime::from_handle accepts any Arc<tokio::runtime::Runtime>, including
single-thread ones.
§Fork protocol (ForkSafeRuntime only)
Call these around every fork() to prevent deadlocks in child processes:
ForkSafeRuntime::before_fork— pauses workersfork()- parent:
ForkSafeRuntime::after_fork_parent— resumes workers - child:
ForkSafeRuntime::after_fork_child— restarts workers on a fresh runtime
Re-exports§
pub use shared_runtime::BasicRuntime;pub use shared_runtime::BlockOnTimeoutError;pub use shared_runtime::BlockingRuntime;pub use shared_runtime::ForkSafeRuntime;pub use shared_runtime::WorkerHandle;pub use shared_runtime::WorkerHandleError;pub use worker::Worker;
Modules§
- shared_
runtime SharedRuntimetrait and its implementations:ForkSafeRuntime,BasicRuntime, and [LocalRuntime].- worker