✨ pending collector iterators
This commit is contained in:
parent
00e448ac31
commit
b043db3f4e
4 changed files with 176 additions and 7 deletions
30
examples/pending.rs
Normal file
30
examples/pending.rs
Normal 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();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue