ferrite_session/internal/session/
fix.rs1use tokio::task;
2
3use crate::internal::{
4 base::*,
5 functional::App,
6};
7
8pub fn fix_session<R, F, A, C>(
9 cont: PartialSession<C, A>
10) -> PartialSession<C, RecX<R, F>>
11where
12 C: Context,
13 R: Context,
14 F: Protocol,
15 A: Protocol,
16 F: RecApp<(RecX<R, F>, R), Applied = A>,
17{
18 unsafe_create_session::<C, RecX<R, F>, _, _>(move |ctx, sender1| async move {
19 let (provider_end_a, client_end_a) = A::create_endpoints();
20
21 let rec_end = RecEndpoint {
22 applied: Box::new(client_end_a),
23 };
24 sender1.send(rec_end).unwrap();
25
26 task::spawn(async move {
27 unsafe_run_session(cont, ctx, provider_end_a).await;
28 });
29 })
30}
31
32pub fn unfix_session<N, C1, C2, A, B, R, F>(
33 _n: N,
34 cont: PartialSession<C2, B>,
35) -> PartialSession<C1, B>
36where
37 B: Protocol,
38 C1: Context,
39 C2: Context,
40 F: Protocol,
41 R: Context,
42 F: RecApp<(RecX<R, F>, R), Applied = A>,
43 A: Protocol,
44 N: ContextLens<C1, RecX<R, F>, A, Target = C2>,
45{
46 unsafe_create_session::<C1, B, _, _>(move |ctx1, provider_end| async move {
47 let (endpoint, ctx2) = N::extract_source(ctx1);
48
49 let receiver1 = endpoint.get_applied();
50
51 let rec_end = receiver1.recv().await.unwrap();
52
53 let client_end = *rec_end.applied.get_applied();
54
55 let ctx3 = N::insert_target(App::new(client_end), ctx2);
56
57 task::spawn(async move {
58 unsafe_run_session(cont, ctx3, provider_end).await;
59 });
60 })
61}