surrealdb_core/ctx/
canceller.rs

1use std::sync::atomic::{AtomicBool, Ordering};
2use std::sync::Arc;
3
4#[derive(Default, Clone)]
5#[non_exhaustive]
6pub struct Canceller {
7	/// A reference to the canceled value of a context.
8	cancelled: Arc<AtomicBool>,
9}
10
11impl Canceller {
12	/// Create a new Canceller
13	pub fn new(cancelled: Arc<AtomicBool>) -> Canceller {
14		Canceller {
15			cancelled,
16		}
17	}
18	/// Cancel the context.
19	pub fn cancel(&self) {
20		self.cancelled.store(true, Ordering::Relaxed);
21	}
22}