pub struct CancelOnDrop(/* private fields */);Expand description
Cancels execution on drop and supports cooperative finalization.
If dropped, it will set the cancelled flag to true.
This is most useful when a spawned job should stop once its owner goes away, e.g. a payload job or a blocking RPC call whose caller disconnected.
Implementations§
Source§impl CancelOnDrop
impl CancelOnDrop
Sourcepub fn is_interrupted(&self) -> bool
pub fn is_interrupted(&self) -> bool
Returns true if the current work should be interrupted.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Returns true if the job was cancelled.
Sourcepub fn request_finalization(&self)
pub fn request_finalization(&self)
Requests that the current work be finalized without cancelling it.
Sourcepub fn is_finalization_requested(&self) -> bool
pub fn is_finalization_requested(&self) -> bool
Returns true if finalization was requested.
Sourcepub fn scope<R>(&self, f: impl FnOnce() -> R) -> R
pub fn scope<R>(&self, f: impl FnOnce() -> R) -> R
Runs f with this as the cancellation state of the current thread, see is_cancelled.
This lets code deep inside f, such as a loop over transactions, observe cancellation
without threading the CancelOnDrop through every call. The previous state of the
thread is restored once f returns or unwinds. Leaving the scope does not cancel.
Trait Implementations§
Source§impl Clone for CancelOnDrop
impl Clone for CancelOnDrop
Source§impl Debug for CancelOnDrop
impl Debug for CancelOnDrop
Source§impl Default for CancelOnDrop
impl Default for CancelOnDrop
Source§impl Drop for CancelOnDrop
impl Drop for CancelOnDrop
Auto Trait Implementations§
impl Freeze for CancelOnDrop
impl RefUnwindSafe for CancelOnDrop
impl Send for CancelOnDrop
impl Sync for CancelOnDrop
impl Unpin for CancelOnDrop
impl UnsafeUnpin for CancelOnDrop
impl UnwindSafe for CancelOnDrop
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> 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 more§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘwhere
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘwhere
S: Into<Dispatch>,
§fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
Source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘwhere
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘwhere
S: Into<Dispatch>,
Source§fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 8 bytes