use std::thread; use testtools::sync::Checkpoint; #[derive(PartialEq, Eq, Hash, Clone)] enum CkPt { First, Second, Third } #[test] fn two() { let sync = Checkpoint::new(); let tsync = sync.clone(); thread::spawn(move || { tsync.waitfor([CkPt::First]).reached(CkPt::Second); }); sync.reached(CkPt::First).waitfor([CkPt::Second]); } #[test] fn multi() { let sync = Checkpoint::new(); let tsync1 = sync.clone(); thread::spawn(move || { tsync1.waitfor([CkPt::First]).reached(CkPt::Second); }); let tsync2 = sync.clone(); thread::spawn(move || { tsync2.waitfor([CkPt::First]).reached(CkPt::Third); }); sync .reached(CkPt::First) .waitfor([CkPt::Second, CkPt::Third]); } #[test] fn async_test() { let sync = Checkpoint::new(); let tokrt = tokio::runtime::Runtime::new().unwrap(); let tsync1 = sync.clone(); let _jh = testtools::thread::spawn_autojoin(move || { tsync1.waitfor([CkPt::First]); tsync1.reached(CkPt::Second); }); let tsync2 = sync.clone(); tokrt.block_on(async { tsync2.reached(CkPt::First); tsync2.async_waitfor([CkPt::Second]).await; }); } // vim: set ft=rust et sw=2 ts=2 sts=2 cinoptions=2 tw=79 :