pending collector iterators

This commit is contained in:
JMARyA 2025-03-09 06:01:38 +01:00
parent 00e448ac31
commit b043db3f4e
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
4 changed files with 176 additions and 7 deletions

30
examples/pending.rs Normal file
View file

@ -0,0 +1,30 @@
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();
}