homestar_runtime/
channel.rs1use crossbeam::channel;
5
6pub type BoundedChannelSender<T> = channel::Sender<T>;
8
9pub type BoundedChannelReceiver<T> = channel::Receiver<T>;
11
12#[allow(dead_code)]
14#[derive(Debug, Clone)]
15pub struct Channel<T> {
16 tx: channel::Sender<T>,
18 rx: channel::Receiver<T>,
20}
21
22impl<T> Channel<T> {
23 pub fn with(capacity: usize) -> (BoundedChannelSender<T>, BoundedChannelReceiver<T>) {
25 let (tx, rx) = channel::bounded(capacity);
26 (tx, rx)
27 }
28
29 pub fn oneshot() -> (BoundedChannelSender<T>, BoundedChannelReceiver<T>) {
31 let (tx, rx) = channel::bounded(1);
32 (tx, rx)
33 }
34}
35
36pub type AsyncChannelSender<T> = flume::Sender<T>;
38
39pub type AsyncChannelReceiver<T> = flume::Receiver<T>;
41
42#[allow(dead_code)]
44#[derive(Debug, Clone)]
45pub struct AsyncChannel<T> {
46 tx: flume::Sender<T>,
48 rx: flume::Receiver<T>,
50}
51
52impl<T> AsyncChannel<T> {
53 pub fn with(capacity: usize) -> (AsyncChannelSender<T>, AsyncChannelReceiver<T>) {
55 let (tx, rx) = flume::bounded(capacity);
56 (tx, rx)
57 }
58
59 pub fn unbounded() -> (AsyncChannelSender<T>, AsyncChannelReceiver<T>) {
61 let (tx, rx) = flume::unbounded();
62 (tx, rx)
63 }
64
65 pub fn oneshot() -> (AsyncChannelSender<T>, AsyncChannelReceiver<T>) {
67 let (tx, rx) = flume::bounded(1);
68 (tx, rx)
69 }
70}