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 {
|
2022-11-23 09:42:59 +00:00
|
|
|
/// Create a new Canceller
|
2021-03-29 15:43:37 +00:00
|
|
|
pub fn new(cancelled: Arc<AtomicBool>) -> Canceller {
|
|
|
|
Canceller {
|
|
|
|
cancelled,
|
|
|
|
}
|
|
|
|
}
|
2022-11-23 09:42:59 +00:00
|
|
|
/// Cancel the context.
|
2022-01-21 12:51:05 +00:00
|
|
|
pub fn cancel(&self) {
|
2022-09-29 07:42:06 +00:00
|
|
|
self.cancelled.store(true, Ordering::Relaxed);
|
2021-03-29 15:43:37 +00:00
|
|
|
}
|
|
|
|
}
|