pub struct CancellationToken { /* private fields */ }Expand description
Cancellation token for signaling shutdown
Lightweight clone-able token that can be passed to async tasks.
§Examples
use adaptive_pipeline_bootstrap::shutdown::ShutdownCoordinator;
use std::time::Duration;
let coordinator = ShutdownCoordinator::new(Duration::from_secs(5));
let token = coordinator.token();
// Pass token to async task
tokio::spawn(async move {
tokio::select! {
_ = token.cancelled() => {
println!("Task received shutdown signal");
}
_ = async { /* do work */ } => {
println!("Task completed normally");
}
}
});
// Later, initiate shutdown
coordinator.initiate_shutdown();Implementations§
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 · 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 CancellationToken
impl RefUnwindSafe for CancellationToken
impl Send for CancellationToken
impl Sync for CancellationToken
impl Unpin 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