Skip to main content

weavatrix_scan/
control.rs

1use std::sync::{
2    Arc,
3    atomic::{AtomicBool, Ordering},
4};
5
6/// A cheap, thread-safe cancellation signal shared by walkers and scanners.
7#[derive(Debug, Clone, Default)]
8pub struct CancellationToken {
9    cancelled: Arc<AtomicBool>,
10}
11
12impl CancellationToken {
13    #[must_use]
14    pub fn new() -> Self {
15        Self::default()
16    }
17
18    pub fn cancel(&self) {
19        self.cancelled.store(true, Ordering::Release);
20    }
21
22    #[must_use]
23    pub fn is_cancelled(&self) -> bool {
24        self.cancelled.load(Ordering::Acquire)
25    }
26}