pub struct CancelToken(/* private fields */);runtime only.Expand description
A token that can be used to cancel multiple operations at once.
When CancelToken::cancel is called, all operations that have been
registered with this token will be cancelled.
It is also possible to use CancelToken::wait to wait until the token is
cancelled, which can be useful for implementing timeouts or other
cancellation-based logic.
To associate a future with this cancel token, use the with_cancel
combinator from the FutureExt trait, which requires nightly feature
future-combinator.
Implementations§
Source§impl CancelToken
impl CancelToken
Sourcepub fn new() -> CancelToken
pub fn new() -> CancelToken
Create a new cancel token.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Check if this token has been cancelled.
Sourcepub fn register<T>(&self, key: &Key<T>)where
T: OpCode,
pub fn register<T>(&self, key: &Key<T>)where
T: OpCode,
Register an operation with this token.
If the token has already been cancelled, the operation will be cancelled
immediately. Usually this method should not be used directly, but rather
through the with_cancel combinator, which requires nightly feature
future-combinator.
Multiple registrations of the same key does nothing, and the key will only be cancelled once.
Sourcepub async fn current() -> Option<CancelToken>
pub async fn current() -> Option<CancelToken>
Try to get the current cancel token associated with the future.
This is done by checking if the current context has a cancel token
associated with it. This will only work with nightly feature
future-combinator turned on; otherwise, None is always returned.
Trait Implementations§
Source§impl Clone for CancelToken
impl Clone for CancelToken
Source§fn clone(&self) -> CancelToken
fn clone(&self) -> CancelToken
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CancelToken
impl Debug for CancelToken
Source§impl Default for CancelToken
impl Default for CancelToken
Source§fn default() -> CancelToken
fn default() -> CancelToken
Source§impl PartialEq for CancelToken
impl PartialEq for CancelToken
impl Eq for CancelToken
Auto Trait Implementations§
impl Freeze for CancelToken
impl !RefUnwindSafe for CancelToken
impl !Send for CancelToken
impl !Sync for CancelToken
impl Unpin for CancelToken
impl UnsafeUnpin for CancelToken
impl !UnwindSafe for CancelToken
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,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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