#![allow( clippy::type_complexity, clippy::too_many_arguments, clippy::large_enum_variant )] use mpstthree::binary::struct_trait::{end::End, recv::Recv, send::Send}; use mpstthree::generate; use mpstthree::role::broadcast::RoleBroadcast; use mpstthree::role::end::RoleEnd; use std::error::Error; static LOOPS: i64 = 100; // Create new roles generate!("rec_and_cancel", 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 EndpointMoreC = MeshedChannels< Send<(), Recv<(), Choose0fromCtoA>>, Send<(), Recv<(), Choose0fromCtoB>>, R2A>, NameC, >; // Creating the MP sessions type EndpointA = MeshedChannels, NameA>; type EndpointB = MeshedChannels, NameB>; type EndpointC = MeshedChannels; 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(())?; let (_, s) = s.recv()?; let s = s.send(())?; endpoint_a(s) }, }) } #[inline] 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(())?; let s = s.send(())?; let (_, s) = s.recv()?; endpoint_b(s) }, }) } #[inline] fn endpoint_c(s: EndpointC) -> Result<(), Box> { let mut temp_s = s; for _ in 1..LOOPS { temp_s = recurs_c(temp_s)?; } let s = choose_mpst_c_to_all!(temp_s, Branching0fromCtoA::Done, Branching0fromCtoB::Done); s.close() } fn recurs_c(s: EndpointC) -> Result> { let s: EndpointMoreC = choose_mpst_c_to_all!(s, Branching0fromCtoA::More, Branching0fromCtoB::More); let s = s.send(())?; let (_, s) = s.recv()?; let s = s.send(())?; let (_, s) = s.recv()?; Ok(s) } fn main() { let (thread_a, thread_b, thread_c) = fork_mpst(endpoint_a, endpoint_b, endpoint_c); thread_a.join().unwrap(); thread_b.join().unwrap(); thread_c.join().unwrap(); }