fetch/cancel.rs
1use std::sync::Arc;
2use std::sync::atomic::{AtomicBool, Ordering};
3
4#[derive(Debug, Clone, Default)]
5pub struct CancelToken(Arc<AtomicBool>);
6
7impl CancelToken {
8 pub fn new() -> Self {
9 Self::default()
10 }
11
12 pub fn cancel(&self) {
13 self.0.store(true, Ordering::SeqCst);
14 }
15
16 pub fn is_cancelled(&self) -> bool {
17 self.0.load(Ordering::SeqCst)
18 }
19}