pub struct WorkerHandle { /* private fields */ }Expand description
Handle to a worker registered on a SharedRuntime.
This handle can be used to stop the worker.
§Warning
If every clone of this handle is dropped without calling WorkerHandle::stop, the worker
remains registered on the SharedRuntime and can only be torn down by shutting the
runtime down. Workers are expected to detect that their input channel has been closed and
park themselves to avoid spinning, but they will not be freed until the runtime stops.
Implementations§
Source§impl WorkerHandle
impl WorkerHandle
Sourcepub fn set_fork_restart(
&self,
restart_on_fork: bool,
) -> Result<(), WorkerHandleError>
pub fn set_fork_restart( &self, restart_on_fork: bool, ) -> Result<(), WorkerHandleError>
Configure whether this worker restarts in a fork child.
When disabled, the next ForkSafeRuntime::after_fork_child call drops the worker without
running its shutdown logic. Language runtimes can disable restart in a managed before-fork
hook, restore it in the parent hook, and replace the inherited worker in the child.
§Errors
Returns an error if the worker has already been stopped or dropped.
Sourcepub async fn stop(self) -> Result<(), WorkerHandleError>
pub async fn stop(self) -> Result<(), WorkerHandleError>
Stop the worker and execute the shutdown logic.
§Errors
Returns an error if the worker has already been stopped.
§Cancel safety
This function is NOT cancel safe and shouldn’t be called in Worker::trigger. If cancelled, the stopped worker can end up in an invalid state if a fork occurs while stopping.
Trait Implementations§
Source§impl Clone for WorkerHandle
impl Clone for WorkerHandle
Source§fn clone(&self) -> WorkerHandle
fn clone(&self) -> WorkerHandle
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more