use std::sync::Arc;
use crate::devices::bug_abort;
use crate::messages::Receiver;
#[derive(Debug, Clone)]
pub(crate) enum Provenance {
New(Receiver),
Existing(Receiver),
}
impl Provenance {
pub(super) fn unpack(self) -> Receiver {
match self {
Provenance::New(rx) => rx,
Provenance::Existing(rx) => rx,
}
}
pub(crate) fn is_new(&self) -> bool {
match self {
Provenance::New(_) => true,
Provenance::Existing(_) => false,
}
}
pub(crate) async fn receive(self) -> Arc<[u8]> {
self.unpack().recv_direct().await.unwrap_or_else(|e| {
bug_abort(format!(
"Failed to receive command from broadcast channel : {}",
e
))
})
}
}