surrealpatch/lib/src/ctx/canceller.rs

22 lines
430 B
Rust
Raw Normal View History

2021-03-29 15:43:37 +00:00
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
#[derive(Default)]
2021-03-29 15:43:37 +00:00
pub struct Canceller {
/// A reference to the canceled value of a context.
cancelled: Arc<AtomicBool>,
}
impl Canceller {
// Create a new Canceller
pub fn new(cancelled: Arc<AtomicBool>) -> Canceller {
Canceller {
cancelled,
}
}
// Cancel the context.
pub fn cancel(&self) {
2021-03-29 15:43:37 +00:00
self.cancelled.store(true, Ordering::SeqCst);
}
}