ferrite_session/internal/protocol/shared/
lock.rs1use core::{
2 future::Future,
3 pin::Pin,
4};
5
6use super::{
7 linear_to_shared::LinearToShared,
8 shared_to_linear::SharedToLinear,
9};
10use crate::internal::base::*;
11
12pub struct Lock<F>
13where
14 F: SharedRecApp<SharedToLinear<LinearToShared<F>>>,
15{
16 pub(crate) unlock: Receiver<(SenderOnce<()>, SenderOnce<LinearToShared<F>>)>,
17}
18
19impl<F> SealedProtocol for Lock<F> where
20 F: SharedRecApp<SharedToLinear<LinearToShared<F>>>
21{
22}
23
24impl<F> Protocol for Lock<F>
25where
26 F: Protocol,
27 F: SharedRecApp<SharedToLinear<LinearToShared<F>>>,
28 F::Applied: Protocol,
29{
30 type ClientEndpoint = ReceiverOnce<Lock<F>>;
31 type ProviderEndpoint = SenderOnce<Lock<F>>;
32
33 fn create_endpoints() -> (Self::ProviderEndpoint, Self::ClientEndpoint)
34 {
35 once_channel()
36 }
37
38 fn forward(
39 client_end: Self::ClientEndpoint,
40 provider_end: Self::ProviderEndpoint,
41 ) -> Pin<Box<dyn Future<Output = ()> + Send + 'static>>
42 {
43 Box::pin(async {
44 let payload = client_end.recv().await.unwrap();
45 provider_end.send(payload).unwrap();
46 })
47 }
48}