pub struct StopHandle { /* private fields */ }Expand description
A spawned background task and the CancellationToken that stops it.
StopHandle::spawn hands the task the same token the handle stores, so
the pairing holds by construction. Dropping the handle detaches the task
(like dropping a bare JoinHandle); stop it with StopHandle::shutdown
instead.
Implementations§
Source§impl StopHandle
impl StopHandle
Sourcepub fn spawn<F, Fut>(task: F) -> Self
pub fn spawn<F, Fut>(task: F) -> Self
Spawn task onto the runtime with a fresh stop token. The closure
receives the token this handle later cancels, so the task observes
exactly the signal Self::cancel and Self::shutdown fire.
Sourcepub fn cancel(&self)
pub fn cancel(&self)
Signal the task to stop without awaiting it. Idempotent —
Self::shutdown cancels again as a no-op. Use this to start a drain
early and overlap it with other teardown work before the final
shutdown().await.
Sourcepub fn abort_handle(&self) -> AbortHandle
pub fn abort_handle(&self) -> AbortHandle
Last-resort abort for a drain that overruns its deadline: dropping a
timed-out Self::shutdown future merely detaches the task, so the
caller takes this handle first and fires it when the timeout lands.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for StopHandle
impl RefUnwindSafe for StopHandle
impl Send for StopHandle
impl Sync for StopHandle
impl Unpin for StopHandle
impl UnsafeUnpin for StopHandle
impl UnwindSafe for StopHandle
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> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<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