use std::sync::Arc;
use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering;
use tokio::sync::Notify;
use tokio::sync::futures::OwnedNotified;
#[derive(Debug)]
pub(crate) struct TokioRuntimeShutdownState {
shutdown: AtomicBool,
notification: Arc<Notify>,
}
impl TokioRuntimeShutdownState {
#[must_use]
pub(crate) fn new() -> Self {
Self {
shutdown: AtomicBool::new(false),
notification: Arc::new(Notify::new()),
}
}
#[must_use]
#[inline]
pub(crate) fn is_shutdown(&self) -> bool {
self.shutdown.load(Ordering::Acquire)
}
pub(crate) fn notification(&self) -> OwnedNotified {
Arc::clone(&self.notification).notified_owned()
}
pub(crate) fn signal(&self) {
self.shutdown.store(true, Ordering::Release);
self.notification.notify_waiters();
}
}