commonware_p2p/authenticated/
mailbox.rs1use futures::{channel::mpsc, SinkExt as _};
2
3#[derive(Debug)]
5pub struct Mailbox<T>(mpsc::Sender<T>);
6
7impl<T> Mailbox<T> {
8 pub fn new(sender: mpsc::Sender<T>) -> Self {
10 Self(sender)
11 }
12
13 #[cfg(test)]
16 pub fn test() -> (Self, mpsc::Receiver<T>) {
17 let (sender, receiver) = mpsc::channel(1);
18 (Self(sender), receiver)
19 }
20}
21
22impl<T> Clone for Mailbox<T> {
23 fn clone(&self) -> Self {
24 Self(self.0.clone())
25 }
26}
27
28impl<T> Mailbox<T> {
29 pub async fn send(&mut self, message: T) -> Result<(), mpsc::SendError> {
31 self.0.send(message).await
32 }
33
34 pub fn is_closed(&self) -> bool {
36 self.0.is_closed()
37 }
38}