Skip to main content

ForkSafeRuntime

Struct ForkSafeRuntime 

Source
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

Source

pub fn with_worker_threads( worker_threads: usize, ) -> Result<Self, SharedRuntimeError>

Creates a ForkSafeRuntime with the given number of tokio worker threads.

Source

pub fn before_fork(&self)

Pauses all workers before fork(). Worker pause errors are logged, not propagated.

Source

pub fn after_fork_parent(&self) -> Result<(), SharedRuntimeError>

Restarts the runtime and workers in the parent after forking; worker state is preserved.

Source

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.

Source

pub fn shutdown( &self, timeout: Option<Duration>, ) -> Result<(), SharedRuntimeError>

Shuts down all workers synchronously. Returns ShutdownTimedOut if timeout is exceeded.

Trait Implementations§

Source§

impl BlockingRuntime for ForkSafeRuntime

Source§

fn block_on<F: Future>(&self, f: F) -> Result<F::Output, Error>

Falls back to a temporary current-thread runtime in the fork window.

Source§

fn block_on_with_timeout<F: Future>( &self, f: F, timeout: Duration, ) -> Result<F::Output, BlockOnTimeoutError>

Drives f to completion, blocking the current thread, but gives up once timeout elapses. Read more
Source§

impl Debug for ForkSafeRuntime

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl SharedRuntime for ForkSafeRuntime

Source§

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>

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)

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more