pub struct CancellationTokenSource { /* private fields */ }Expand description
A source that can cancel associated CancellationTokens.
§Example
use async_cancellation_token::CancellationTokenSource;
let cts = CancellationTokenSource::new();
let token = cts.token();
assert!(!cts.is_cancelled());
cts.cancel();
assert!(cts.is_cancelled());Implementations§
Source§impl CancellationTokenSource
impl CancellationTokenSource
Sourcepub fn token(&self) -> CancellationToken
pub fn token(&self) -> CancellationToken
Get a CancellationToken associated with this source.
Sourcepub fn cancel(&self)
pub fn cancel(&self)
Cancel all associated tokens.
This triggers any registered callbacks and wakes all wakers.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Check if this source has been cancelled.
Trait Implementations§
Source§impl Clone for CancellationTokenSource
impl Clone for CancellationTokenSource
Source§fn clone(&self) -> CancellationTokenSource
fn clone(&self) -> CancellationTokenSource
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for CancellationTokenSource
impl !RefUnwindSafe for CancellationTokenSource
impl !Send for CancellationTokenSource
impl !Sync for CancellationTokenSource
impl Unpin for CancellationTokenSource
impl !UnwindSafe for CancellationTokenSource
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