pub struct CancelToken(/* private fields */);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.
Implementations§
Source§impl CancelToken
impl CancelToken
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new cancel token.
§Panics
CancelToken can only be created within compio runtime environment.
This will panic without a runtime.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Check if this token has been cancelled.
Sourcepub fn register<T: OpCode>(&self, key: &Key<T>)
pub fn register<T: OpCode>(&self, key: &Key<T>)
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.
Multiple registrations of the same key does nothing, and the key will only be cancelled once.
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§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,
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