ferrite_session/internal/protocol/value/
receive.rs1use core::{
2 future::Future,
3 marker::PhantomData,
4 pin::Pin,
5};
6
7use crate::internal::base::*;
8
9pub struct ReceiveValue<T, A>(PhantomData<(T, A)>);
10
11impl<T, A> SealedProtocol for ReceiveValue<T, A> {}
12
13impl<T, A> Protocol for ReceiveValue<T, A>
14where
15 T: Send + 'static,
16 A: Protocol,
17{
18 type ClientEndpoint = SenderOnce<(Value<T>, A::ProviderEndpoint)>;
19 type ProviderEndpoint = ReceiverOnce<(Value<T>, A::ProviderEndpoint)>;
20
21 fn create_endpoints() -> (Self::ProviderEndpoint, Self::ClientEndpoint)
22 {
23 let (sender, receiver) = once_channel();
24 (receiver, sender)
25 }
26
27 fn forward(
28 client_end: Self::ClientEndpoint,
29 provider_end: Self::ProviderEndpoint,
30 ) -> Pin<Box<dyn Future<Output = ()> + Send + 'static>>
31 {
32 Box::pin(async {
33 let payload = provider_end.recv().await.unwrap();
34 client_end.send(payload).unwrap();
35 })
36 }
37}
38
39impl<X, T, A> RecApp<X> for ReceiveValue<T, A>
40where
41 X: Send + 'static,
42 T: Send + 'static,
43 A: RecApp<X>,
44{
45 type Applied = ReceiveValue<T, A::Applied>;
46}
47
48impl<T, A, X> SharedRecApp<X> for ReceiveValue<T, A>
49where
50 T: Send + 'static,
51 A: SharedRecApp<X>,
52{
53 type Applied = ReceiveValue<T, A::Applied>;
54}