use tokio::sync::oneshot;
use tokio_util::sync::CancellationToken;
use crate::core::outcome::TaskOutcome;
pub(crate) type OutcomeTx = oneshot::Sender<TaskOutcome>;
#[derive(Clone, Debug)]
pub(crate) struct RemovalCompletion {
logical: CancellationToken,
physical: CancellationToken,
}
impl RemovalCompletion {
pub(crate) fn new() -> Self {
Self {
logical: CancellationToken::new(),
physical: CancellationToken::new(),
}
}
pub(crate) async fn wait(&self) {
self.logical.cancelled().await;
}
#[cfg(feature = "controller")]
pub(crate) async fn wait_physical(&self) {
self.logical.cancelled().await;
self.physical.cancelled().await;
}
pub(super) fn is_complete(&self) -> bool {
self.logical.is_cancelled()
}
#[cfg(test)]
pub(super) fn is_physical_complete(&self) -> bool {
self.physical.is_cancelled()
}
pub(super) fn complete_logical(&self) {
self.logical.cancel();
}
pub(super) fn complete_physical(&self) {
self.physical.cancel();
}
pub(super) fn shares_physical_latch(&self, other: &Self) -> bool {
self.physical == other.physical
}
}