use mpstthree::binary::close::close;
use mpstthree::binary::struct_trait::end::*;
use mpstthree::binary::struct_trait::session::*;
use mpstthree::binary_atmp::choose::{choose_left, ChooseTimed};
use mpstthree::binary_atmp::offer::offer_either;
use std::collections::HashMap;
use std::error::Error;
use std::thread::sleep;
use std::time::{Duration, Instant};
pub fn offer_upper_timeout_panics() {
assert!(|| -> Result<(), Box<dyn Error>> {
let mut all_clocks = HashMap::<char, Instant>::new();
all_clocks.insert('a', Instant::now());
sleep(Duration::from_secs(1));
let (sender, receiver) = ChooseTimed::<End, End, 'a', 1, true, 2, true, ' '>::new();
let _ = choose_left::<End, End, 'a', 1, true, 2, true, ' '>(&mut all_clocks, sender)?;
sleep(Duration::from_secs(3));
offer_either(
&mut all_clocks,
receiver,
|_all_clocks: &mut HashMap<char, Instant>, s: End| close(s),
|_all_clocks: &mut HashMap<char, Instant>, s: End| close(s),
)
}()
.is_err());
}
pub fn offer_lower_timeout_panics() {
assert!(|| -> Result<(), Box<dyn Error>> {
let mut all_clocks = HashMap::<char, Instant>::new();
all_clocks.insert('a', Instant::now());
sleep(Duration::from_secs(1));
let (sender, receiver) = ChooseTimed::<End, End, 'a', 1, true, 2, true, ' '>::new();
let _ = choose_left::<End, End, 'a', 1, true, 2, true, ' '>(&mut all_clocks, sender)?;
let clock_a = all_clocks.get_mut(&'a').unwrap();
*clock_a = Instant::now();
offer_either(
&mut all_clocks,
receiver,
|_all_clocks: &mut HashMap<char, Instant>, s: End| close(s),
|_all_clocks: &mut HashMap<char, Instant>, s: End| close(s),
)
}()
.is_err());
}