use async_channel::{ unbounded as unbounded_async, Receiver as AsyncReceiver, Sender as AsyncSender, }; use crossbeam::channel::{unbounded, Receiver, Sender}; pub struct Channel { pub tx: Sender, pub rx: Receiver, } impl Channel { pub fn new() -> Self { let (tx, rx) = unbounded::(); Self { tx, rx } } pub fn send(&self, msg: T) { self.tx.send(msg).unwrap() } pub fn recv(&self) -> T { self.rx.recv().unwrap() } pub fn is_empty(&self) -> bool { self.rx.is_empty() } } impl Default for Channel { fn default() -> Self { Channel::new() } } pub struct AsyncChannel { pub tx: AsyncSender, pub rx: AsyncReceiver, } impl AsyncChannel { pub fn new() -> Self { let (tx, rx) = unbounded_async::(); Self { tx, rx } } pub async fn send(&self, msg: T) { self.tx.send(msg).await.unwrap() } pub async fn recv(&self) -> T { self.rx.recv().await.unwrap() } pub fn is_empty(&self) -> bool { self.rx.is_empty() } } impl Default for AsyncChannel { fn default() -> Self { AsyncChannel::new() } }