use mpstthree::binary::struct_trait::{end::End, recv::Recv, send::Send}; use mpstthree::role::broadcast::RoleBroadcast; use mpstthree::role::end::RoleEnd; use mpstthree::{generate, create_fn_choose_mpst_multi_to_all_bundle}; use std::error::Error; // Create new roles generate!("basic", MeshedChannels, A, B, C); // Types // Send/Recv type RS = Recv<(), Send<(), End>>; type SR = Send<(), Recv<(), End>>; // Roles type R2A = RoleA>; type R2B = RoleB>; type R2C = RoleC>; // A enum Branching0fromCtoA { More(MeshedChannels>, R2C>>, NameA>), Done(MeshedChannels), } type RecursAtoC = Recv; // B enum Branching0fromCtoB { More(MeshedChannels>, R2C>>, NameB>), Done(MeshedChannels), } type RecursBtoC = Recv; // C type Choose0fromCtoA = Send; type Choose0fromCtoB = Send; type EndpointDoneC = MeshedChannels; type EndpointMoreC = MeshedChannels< Send<(), Recv<(), Choose0fromCtoA>>, Send<(), Recv<(), Choose0fromCtoB>>, RoleA>>>, NameC, >; // Creating the MP sessions type EndpointA = MeshedChannels, NameA>; type EndpointB = MeshedChannels, NameB>; type EndpointC = MeshedChannels; create_fn_choose_mpst_multi_to_all_bundle!( done_from_c_to_all, more_from_c_to_all, => Done, More, => EndpointDoneC, EndpointMoreC, => Branching0fromCtoA, Branching0fromCtoB, => NameA, NameB, => NameC, MeshedChannels, 3 ); fn endpoint_a(s: EndpointA) -> Result<(), Box> { offer_mpst!( s, { Branching0fromCtoA::Done(s) => { s.close() }, Branching0fromCtoA::More(s) => { let (_, s) = s.recv(); let (_, s) = s.send(()).recv(); let s = s.send(()); endpoint_a(s) }, } ) } fn endpoint_b(s: EndpointB) -> Result<(), Box> { offer_mpst!( s, { Branching0fromCtoB::Done(s) => { s.close() }, Branching0fromCtoB::More(s) => { let (_, s) = s.recv(); let (_, s) = s.send(()).send(()).recv(); endpoint_b(s) }, } ) } fn endpoint_c(s: EndpointC) -> Result<(), Box> { recurs_c(s, LOOPS) } fn recurs_c(s: EndpointC, index: i64) -> Result<(), Box> { match index { 0 => done_from_c_to_all(s).close(), i => { let (_, s) = more_from_c_to_all(s).send(()).recv(); let (_, s) = s.send(()).recv(); recurs_c(s, i - 1) } } } ///////////////////////////////////////// pub fn main() { let (thread_a, thread_b, thread_c) = fork_mpst(endpoint_a, endpoint_b, endpoint_c); assert!(thread_a.join().is_err()); assert!(thread_b.join().is_err()); assert!(thread_c.join().is_err()); } ///////////////////////// static LOOPS: i64 = 15;