use std::sync::mpsc;
use super::{ErrorKind, ExecutionError};
pub fn channel() -> (Sender, Receiver) {
let (tx, rx) = mpsc::channel();
(Sender(tx), Receiver(rx))
}
#[derive(Debug)]
pub struct Receiver(mpsc::Receiver<Result<(), ExecutionError>>);
impl Receiver {
pub fn with_result(result: Result<(), ExecutionError>) -> Self {
let (tx, rx) = channel();
tx.send(result);
rx
}
pub(crate) fn wait(self) -> Result<(), ExecutionError> {
self.0.recv().unwrap_or_else(|_| {
Err(ExecutionError::new(
ErrorKind::Unexpected,
"An error during waiting for deployment status occurred",
))
})
}
}
#[derive(Debug, Clone)]
pub struct Sender(mpsc::Sender<Result<(), ExecutionError>>);
impl Sender {
pub fn send(self, deployment_status: Result<(), ExecutionError>) {
if self.0.send(deployment_status).is_err() {
log::warn!("Unable to send deployment status: an error occurred",);
}
}
}