2021-03-29 15:43:37 +00:00
|
|
|
use std::sync::atomic::{AtomicBool, Ordering};
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
2022-01-21 12:51:05 +00:00
|
|
|
#[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.
|
2022-01-21 12:51:05 +00:00
|
|
|
pub fn cancel(&self) {
|
2021-03-29 15:43:37 +00:00
|
|
|
self.cancelled.store(true, Ordering::SeqCst);
|
|
|
|
}
|
|
|
|
}
|