Skip to main content

Crate libdd_shared_runtime

Crate libdd_shared_runtime 

Source
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

RuntimeTargetThreadsFork-safeblock_onWhen to use
ForkSafeRuntimenativemultiyes — full protocolyesDefault for native code that may run in a forking process (e.g. Ruby, Python runtimes).
BasicRuntimenativemulti*noyesNative code where fork() is not a concern; optionally share an existing Arc<tokio::runtime::Runtime> via BasicRuntime::from_handle.
[LocalRuntime]wasm32singlen/anoWebAssembly; 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:

  1. ForkSafeRuntime::before_fork — pauses workers
  2. fork()
  3. parent: ForkSafeRuntime::after_fork_parent — resumes workers
  4. 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::SharedRuntime;
pub use shared_runtime::SharedRuntimeError;
pub use shared_runtime::WorkerHandle;
pub use shared_runtime::WorkerHandleError;
pub use worker::Worker;

Modules§

shared_runtime
SharedRuntime trait and its implementations: ForkSafeRuntime, BasicRuntime, and [LocalRuntime].
worker