use std::time::Duration; use comrade::{job::LabelPendingTaskIterator, service::ServiceManager, worker}; #[worker(5)] pub fn wait_work(i: u64) -> u64 { std::thread::sleep(Duration::from_secs(i)); i } fn main() { let mut s = ServiceManager::new().mode(comrade::service::ServiceMode::Decay); s = wait_work_init(s); let s = s.spawn(); let mut pending = Vec::new(); for i in 0..5 { pending.push((i, wait_work_async(rand::random_range(0..5)))); } for (res, label) in LabelPendingTaskIterator(pending) { println!("Got value back {res:?} for {label:?}"); } wait_work_shutdown(); s.join().unwrap(); }