pub(crate) struct Interlock {
pub sender: Location,
pub receiver: Location,
}
pub(crate) enum Location {
Local,
Sending(tokio::sync::oneshot::Receiver<()>),
Remote,
}
impl Location {
pub fn check_local(&mut self) -> bool {
match self {
Self::Local => true,
Self::Sending(rx) => match rx.try_recv() {
Ok(()) => {
*self = Self::Remote;
false
}
Err(tokio::sync::oneshot::error::TryRecvError::Empty) => false,
Err(tokio::sync::oneshot::error::TryRecvError::Closed) => {
*self = Self::Local;
true
}
},
Self::Remote => false,
}
}
pub fn start_send(&mut self) -> tokio::sync::oneshot::Sender<()> {
let (tx, rx) = tokio::sync::oneshot::channel();
*self = Self::Sending(rx);
tx
}
}