pub struct WorkerHandle { /* private fields */ }Expand description
Handle to a running worker task.
Cheap to clone — internally Arc’d so multiple call sites can hold
references. Dropping the last clone does NOT trigger shutdown; callers
should explicitly invoke Self::shutdown on graceful-stop paths.
Implementations§
Source§impl WorkerHandle
impl WorkerHandle
Sourcepub fn is_shutting_down(&self) -> bool
pub fn is_shutting_down(&self) -> bool
Returns true if the worker has been signaled to stop.
Sourcepub fn cancellation_token(&self) -> CancellationToken
pub fn cancellation_token(&self) -> CancellationToken
Returns a child CancellationToken tied to the worker’s lifecycle.
Child tokens are cancelled when the worker itself is shut down. Useful when downstream subtasks want to share the same shutdown semantics.
CancellationToken is leaked here from tokio-util deliberately:
it is the de-facto-standard cooperative cancellation primitive in the
tokio ecosystem, and exposing it gives consumers direct
interoperability with the rest of their async code.
Sourcepub async fn shutdown(&self)
pub async fn shutdown(&self)
Signals the worker to stop and waits for it to drain.
The worker finishes its current job (if any), declines to claim a new one, and exits. If the drain timeout elapses first, the task is aborted and any in-flight claim leaks until the lease expires.
Calling shutdown more than once is safe — subsequent calls observe
the already-shut-down state and return immediately.
Sourcepub async fn abort(&self)
pub async fn abort(&self)
Aborts the worker task without waiting for graceful drain.
In-flight claims leak until their lease expires. Prefer
Self::shutdown except in emergency shutdown paths.
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 moreAuto Trait Implementations§
impl !RefUnwindSafe for WorkerHandle
impl !UnwindSafe for WorkerHandle
impl Freeze for WorkerHandle
impl Send for WorkerHandle
impl Sync for WorkerHandle
impl Unpin for WorkerHandle
impl UnsafeUnpin for WorkerHandle
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request