Skip to main content

CancelToken

Struct CancelToken 

Source
pub struct CancelToken { /* private fields */ }
Expand description

A handle into a cancel subtree.

Clone yields the same identity (same node), like the legacy token. A cancel() cancels this token’s own subtree (epoch/fetch cancels are legitimate); ancestors and siblings are unaffected. Two constructors mint a fresh subtree root instead of deriving from a parent — root, the owning master a subsystem holds and cancels on teardown, and never, a sentinel that is never cancelled. Both are covered by the cancel_root_sites guard.

Implementations§

Source§

impl CancelToken

Source

pub fn cancel(&self)

Cancel this token’s subtree.

Source

pub fn cancelled(&self) -> Cancelled<'_>

Future that resolves once this token’s subtree is cancelled. Cancel-safe in tokio::select!: dropping it unregisters its slot.

Source

pub fn child(&self) -> Self

Derive a child token rooted at this token’s subtree.

Source

pub fn is_cancelled(&self) -> bool

Source

pub fn never() -> Self

A token that is never cancelled — a placeholder where a token is required but no cancellation source exists. The sentinel sibling of root; both mint a fresh subtree root.

Source

pub fn on_cancel<F>(&self, waker: F) -> CancelWakerGuard
where F: Fn() + Send + Sync + 'static,

Register a synchronous waker fired when this token is cancelled — the sync counterpart to cancelled for a thread parked on a (flash-aware) Condvar/Notify. Registered on THIS node only; an ancestor cancel() reaches it through the down-propagation drain.

The waker runs on the cancelling thread: keep it cheap, non-blocking, and idempotent. If the token is already cancelled it fires immediately. The returned guard unregisters the waker on drop — hold it for the wait’s lifetime.

Source

pub fn root() -> Self

Mint a fresh root of a new cancel subtree — the owning master a subsystem holds and cancels on teardown. Drop is passive: dropping the root does not cancel its subtree; teardown is an explicit cancel(). Minted only at owner sites (enforced by the cancel_root_sites guard). For a token that is structurally required but never cancelled, use never instead.

Trait Implementations§

Source§

impl BitOr<CancelGroup> for CancelToken

Source§

type Output = CancelGroup

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: CancelGroup) -> CancelGroup

Performs the | operation. Read more
Source§

impl BitOr<CancelToken> for CancelGroup

Source§

type Output = CancelGroup

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: CancelToken) -> Self

Performs the | operation. Read more
Source§

impl Clone for CancelToken

Source§

fn clone(&self) -> CancelToken

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CancelToken

Source§

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

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

impl From<CancelToken> for CancelGroup

Source§

fn from(token: CancelToken) -> Self

Converts to this type from the input type.

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> MaybeSync for T
where T: Sync,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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