Skip to main content

SharedRuntime

Trait SharedRuntime 

Source
pub trait SharedRuntime {
    // Required methods
    fn new() -> Result<Self, SharedRuntimeError>
       where Self: Sized;
    fn spawn_worker<T: Worker + Sync + 'static>(
        &self,
        worker: T,
        restart_on_fork: bool,
    ) -> Result<WorkerHandle, SharedRuntimeError>;
    fn shutdown_async(&self) -> impl Future<Output = ()> + MaybeSend + '_
       where Self: Sync;
}
Expand description

Common interface for all SharedRuntime implementations.

§Choosing an implementation

SituationRuntime
Native, host process may call fork(2)ForkSafeRuntime
Native, caller owns a tokio runtime and wants to share itBasicRuntime
Wasm / single-threaded JS event loop[LocalRuntime]

Sync entry points (e.g. a blocking build or send) additionally require R: BlockingRuntime, which only the native implementations satisfy.

Required Methods§

Source

fn new() -> Result<Self, SharedRuntimeError>
where Self: Sized,

Creates a new instance of the runtime with default configuration.

Used as a fallback by callers (e.g. crate::shared_runtime consumers) that want to auto-construct a runtime when one was not supplied; concrete runtimes additionally expose richer inherent constructors (e.g. with_worker_threads, from_handle).

Source

fn spawn_worker<T: Worker + Sync + 'static>( &self, worker: T, restart_on_fork: bool, ) -> Result<WorkerHandle, SharedRuntimeError>

Spawns a worker. restart_on_fork = true causes ForkSafeRuntime::after_fork_child to reset and restart it; false drops it without calling shutdown. BasicRuntime and [LocalRuntime] ignore this flag — they do not implement a fork protocol.

Source

fn shutdown_async(&self) -> impl Future<Output = ()> + MaybeSend + '_
where Self: Sync,

Shuts down all tracked workers. The runtime itself is not torn down — call ForkSafeRuntime::shutdown (native only) to also drop the tokio runtime.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§