ferrite_session/internal/session/shared/
accept.rs1use core::future::Future;
2
3use crate::internal::{
4 base::*,
5 functional::*,
6 protocol::{
7 LinearToShared,
8 Lock,
9 SharedToLinear,
10 },
11};
12
13pub fn accept_shared_session<F>(
14 cont: impl Future<Output = PartialSession<(Lock<F>, ()), F::Applied>>
15 + Send
16 + 'static
17) -> SharedSession<LinearToShared<F>>
18where
19 F: Protocol,
20 F: SharedRecApp<SharedToLinear<LinearToShared<F>>>,
21 F::Applied: Protocol,
22{
23 unsafe_create_shared_session(
24 move |receiver1: Receiver<(
25 SenderOnce<()>,
26 SenderOnce<LinearToShared<F>>,
27 )>| async move {
28 let (lock_producer_end, lock_client_end) = <Lock<F>>::create_endpoints();
29
30 let (producer_end, client_end) = F::Applied::create_endpoints();
31
32 let m_sender1 = receiver1.recv().await;
33
34 if let Some((sender5, sender6)) = m_sender1 {
35 sender6
36 .send(LinearToShared {
37 linear: Box::new(client_end),
38 })
39 .unwrap();
40
41 sender5.send(()).unwrap();
42
43 lock_producer_end.send(Lock { unlock: receiver1 }).unwrap();
44
45 debug!("[accept_shared_session] calling cont");
46
47 unsafe_run_session(
48 cont.await,
49 (App::new(lock_client_end), ()),
50 producer_end,
51 )
52 .await;
53
54 debug!("[accept_shared_session] returned from cont");
55 } else {
56 }
59 },
60 )
61}