Expand description
This crate provides a Token that can be used to co-operatively
signal when an operation should be canceled.
use cancel::{Canceled, Token};
use std::time::Duration;
fn do_something(token: &Token) -> Result<bool, Canceled> {
loop {
token.check_cancel()?;
// process more stuff here
}
Ok(true)
}
fn start_something() -> Result<bool, Canceled> {
let token = Token::with_duration(Duration::new(10, 0));
do_something(&token)
}Structsยง
- The Err value returned from
Token::check_cancel. It indicates that theTokenwas canceled and that the operation should cease. - A cancellation token. It tracks the state and holds an optional deadline for the operation. To share
Tokenacross threads, wrap it in astd::sync::Arc.