1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use crate::tracers::tracer::{self, ControlReceiver, ControlSender};
use futures::{Stream, StreamExt};
use rill_protocol::flow::core;
use tokio_stream::wrappers::UnboundedReceiverStream;
pub struct Link<T: core::Flow> {
tx: ControlSender<T>,
rx: ControlReceiver<T>,
}
impl<T: core::Flow> Link<T> {
pub fn new() -> Self {
let (tx, rx) = tracer::channel();
Self { tx, rx }
}
pub fn sender(&self) -> ControlSender<T> {
self.tx.clone()
}
pub fn receiver(self) -> ControlReceiver<T> {
self.rx
}
pub fn actions(self) -> impl Stream<Item = T::Action> {
let stream = UnboundedReceiverStream::new(self.rx);
stream.filter_map(|envelope| async move { envelope.activity.to_action() })
}
}