pub struct ForkSafeRuntime { /* private fields */ }Expand description
Owns a tokio runtime and manages [PausableWorker]s on it.
Supports the full fork protocol (before_fork /
after_fork_parent /
after_fork_child) and synchronous shutdown.
Implementations§
Source§impl ForkSafeRuntime
impl ForkSafeRuntime
Sourcepub fn with_worker_threads(
worker_threads: usize,
) -> Result<Self, SharedRuntimeError>
pub fn with_worker_threads( worker_threads: usize, ) -> Result<Self, SharedRuntimeError>
Creates a ForkSafeRuntime with the given number of tokio worker threads.
Sourcepub fn before_fork(&self)
pub fn before_fork(&self)
Pauses all workers before fork(). Worker pause errors are logged, not propagated.
Sourcepub fn after_fork_parent(&self) -> Result<(), SharedRuntimeError>
pub fn after_fork_parent(&self) -> Result<(), SharedRuntimeError>
Restarts the runtime and workers in the parent after forking; worker state is preserved.
Sourcepub fn after_fork_child(&self) -> Result<(), SharedRuntimeError>
pub fn after_fork_child(&self) -> Result<(), SharedRuntimeError>
Reinitializes the runtime in the child after forking.
Workers with restart_on_fork = true are reset and restarted; others are dropped
without shutdown.
Trait Implementations§
Source§impl BlockingRuntime for ForkSafeRuntime
impl BlockingRuntime for ForkSafeRuntime
Source§impl Debug for ForkSafeRuntime
impl Debug for ForkSafeRuntime
Source§fn new() -> Result<Self, SharedRuntimeError>
fn new() -> Result<Self, SharedRuntimeError>
Creates a new instance of the runtime with default configuration. Read more
Source§fn spawn_worker<T: Worker + Sync + 'static>(
&self,
worker: T,
restart_on_fork: bool,
) -> Result<WorkerHandle, SharedRuntimeError>
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§async fn shutdown_async(&self)
async fn shutdown_async(&self)
Shuts down all tracked workers. The runtime itself is not torn down — call
ForkSafeRuntime::shutdown (native only) to also drop the tokio runtime.Auto Trait Implementations§
impl !Freeze for ForkSafeRuntime
impl RefUnwindSafe for ForkSafeRuntime
impl Send for ForkSafeRuntime
impl Sync for ForkSafeRuntime
impl Unpin for ForkSafeRuntime
impl UnsafeUnpin for ForkSafeRuntime
impl UnwindSafe for ForkSafeRuntime
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more