use std::thread; use recstrm::*; #[derive(PartialEq, Eq, Hash, Clone)] enum Checkpoint { PreDrop, PostDrop, NoneCheck } #[test] fn tryrecv() { let sync = testtools::sync::Checkpoint::new(); let (tx, rx) = Builder::new().queue_size(8).build::<_, ()>(); let tsync = sync.clone(); thread::spawn(move || { tx.send("hello").unwrap(); tsync .reached(Checkpoint::PreDrop) .waitfor([Checkpoint::NoneCheck]); drop(tx); tsync.reached(Checkpoint::PostDrop); }); // Wait until sender has sent a node sync.waitfor([Checkpoint::PreDrop]); let TryRecv::Some(node) = rx.try_recv().unwrap() else { panic!("Unexpectedly not TryRecv::Some()"); }; assert_eq!(node, "hello"); sync.waitfor([Checkpoint::PreDrop]); let TryRecv::None = rx.try_recv().unwrap() else { panic!("Unexpectedly did not get TryRecv::None"); }; sync .reached(Checkpoint::NoneCheck) .waitfor([Checkpoint::PostDrop]); let TryRecv::EOF = rx.try_recv().unwrap() else { panic!("Unexpectedly did not get TryRecv::EOF"); }; } // vim: set ft=rust et sw=2 ts=2 sts=2 cinoptions=2 tw=79 :