use std::sync::mpsc::channel; use threadbath::ThreadPool; #[test] fn new() { let _pool = ThreadPool::new(2); } #[test] fn sync_channel() { let n_workers = 4; let n_jobs = 8; let pool = ThreadPool::new(n_workers); let (tx, rx) = channel(); for _ in 0..n_jobs { let tx = tx.clone(); pool.execute(move || { tx.send(1).expect("Failed to send to channel"); }); } assert_eq!(rx.iter().take(n_jobs).fold(0, |a, b| a + b), 8); }