Skip to main content

radiate_core/domain/sync/
channel.rs

1use std::sync::{Arc, mpsc};
2
3pub struct CommandChannel<T> {
4    sender: Arc<mpsc::Sender<T>>,
5    receiver: mpsc::Receiver<T>,
6}
7
8impl<T> CommandChannel<T> {
9    pub fn new() -> Self {
10        let (tx, rx) = mpsc::channel();
11        Self {
12            sender: Arc::new(tx),
13            receiver: rx,
14        }
15    }
16
17    pub fn dispatcher(&self) -> Arc<mpsc::Sender<T>> {
18        Arc::clone(&self.sender)
19    }
20
21    pub fn next(&self) -> Result<T, mpsc::RecvError> {
22        self.receiver.recv()
23    }
24}