commonware_p2p/authenticated/
mailbox.rs1use futures::channel::mpsc;
2
3#[derive(Debug)]
5pub struct Mailbox<T>(pub(crate) mpsc::Sender<T>);
6
7impl<T> Mailbox<T> {
8 pub fn new(size: usize) -> (Self, mpsc::Receiver<T>) {
10 let (sender, receiver) = mpsc::channel(size);
11 (Self(sender), receiver)
12 }
13}
14
15impl<T> Clone for Mailbox<T> {
16 fn clone(&self) -> Self {
17 Self(self.0.clone())
18 }
19}
20
21#[derive(Debug)]
23pub struct UnboundedMailbox<T>(pub(crate) mpsc::UnboundedSender<T>);
24
25impl<T> UnboundedMailbox<T> {
26 pub fn new() -> (Self, mpsc::UnboundedReceiver<T>) {
28 let (sender, receiver) = mpsc::unbounded();
29 (Self(sender), receiver)
30 }
31}
32
33impl<T> Clone for UnboundedMailbox<T> {
34 fn clone(&self) -> Self {
35 Self(self.0.clone())
36 }
37}