[−][src]Struct cancel::Token
A cancellation token.
It tracks the state and holds an optional deadline for the operation.
To share Token
across threads, wrap it in a std::sync::Arc
.
Methods
impl Token
[src]
pub fn new() -> Self
[src]
Create a new Token with no deadline. The token
will be marked as canceled only once Token::cancel
has been called.
pub fn with_duration(duration: Duration) -> Self
[src]
Create a new Token with a deadline set to the current
clock plus the specified duration. The token will be
marked as canceled either when Token::cancel
is
called, or when the operation calls either Token::is_canceled
or Token::check_cancel
and the current clock exceeds
the computed deadline.
pub fn with_deadline(deadline: Instant) -> Self
[src]
Create a new Token with a deadline set to the specified
instant. The token will be marked as canceled either when
Token::cancel
is called, or when the operation calls
either Token::is_canceled
or Token::check_cancel
and
the current clock exceeds the specified deadline.
pub fn cancel(&self)
[src]
Explicitly mark the token as being canceled. This method is async signal safe.
pub fn was_canceled(&self) -> bool
[src]
Check whether the token was canceled.
This method is intended to be called by code that initiated
(rather than performed) an operation to test whether that
operation was successful.
If you want to test for cancellation in the body of your
processing code you should use either Token::is_canceled
or Token::check_cancel
.
Using Token::check_cancel
to propagate a Result
value
is often a cleaner design than using Token::was_canceled
.
pub fn is_canceled(&self) -> bool
[src]
Test whether an ongoing operation should cease due to cancellation. If a deadline has been set, the current clock will be evaluated and compared against the deadline, setting the state to canceled if appropriate. Returns true if the operation has been canceled.
pub fn check_cancel(&self) -> Result<(), Canceled>
[src]
Test whether an ongoing operation should cease
due to cancellation, propagating a Canceled
error value
if the operation has been canceled.
If a deadline has been set, the current clock will be evaluated
and compared against the deadline, setting the state to canceled
if appropriate.
Trait Implementations
Auto Trait Implementations
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,