You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

28 lines
621 B

use crate::UErrorBt;
use crossbeam::channel::{self, Receiver, Sender};
use once_cell::sync::OnceCell;
type ChanError = UErrorBt;
static ERR_CHAN: OnceCell<ErrChan> = OnceCell::new();
pub struct ErrChan {
tx: Sender<ChanError>,
rx: Receiver<ChanError>,
}
impl ErrChan {
fn get() -> &'static Self {
ERR_CHAN.get_or_init(|| {
let (tx, rx) = channel::bounded(20);
Self { tx, rx }
})
}
pub fn send(msg: impl Into<UErrorBt>) {
Self::get().tx.send(msg.into()).unwrap()
}
pub fn recv() -> ChanError {
Self::get().rx.recv().unwrap()
}
}