pub struct CancellationToken { /* private fields */ }Expand description
Implementations§
Source§impl CancellationToken
impl CancellationToken
Sourcepub fn child(&self) -> Self
pub fn child(&self) -> Self
Create a child token. Cancelling this token (or any ancestor) also cancels the child and wakes its waiters. Cancelling the child does NOT cancel the parent.
Sourcepub fn cancel(&self)
pub fn cancel(&self)
Cancel this token. All futures awaiting cancelled()
will resolve. Child tokens are also cancelled.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Whether this token has been cancelled. O(1) — single atomic load. Parent cancellation propagates eagerly (sets the child’s flag), so no chain traversal needed.
Sourcepub fn drop_guard(self) -> DropGuard
pub fn drop_guard(self) -> DropGuard
Returns a guard that cancels this token when dropped.
Useful for ensuring cancellation on scope exit or panic.
Sourcepub fn cancelled(&self) -> Cancelled
pub fn cancelled(&self) -> Cancelled
Returns a future that resolves when this token is cancelled.
The returned Cancelled is !Unpin. .await auto-pins; for
hot loops re-polling the same future, pin once outside:
ⓘ
let cancelled = token.cancelled();
let mut cancelled = std::pin::pin!(cancelled);
loop { /* poll cancelled.as_mut() */ }Trait Implementations§
Source§impl Clone for CancellationToken
impl Clone for CancellationToken
Source§fn clone(&self) -> CancellationToken
fn clone(&self) -> CancellationToken
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for CancellationToken
impl Debug for CancellationToken
Auto Trait Implementations§
impl Freeze for CancellationToken
impl !RefUnwindSafe for CancellationToken
impl Send for CancellationToken
impl Sync for CancellationToken
impl Unpin for CancellationToken
impl UnsafeUnpin for CancellationToken
impl !UnwindSafe for CancellationToken
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
Mutably borrows from an owned value. Read more