iterated fn + defer + retry

This commit is contained in:
JMARyA 2025-03-10 11:27:20 +01:00
parent c010cc13e8
commit 18c663fcdb
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
11 changed files with 678 additions and 65 deletions

View file

@ -1,7 +1,7 @@
use std::time::Duration;
use comrade::{
job::{JobDispatcher, JobOrder},
job::{JobDispatcher, JobOrder, LabelPendingTaskIterator},
service::ServiceManager,
worker,
};
@ -22,6 +22,18 @@ pub fn multiply(a: i32, b: i32) -> i32 {
a * b
}
pub fn batch_work() {
let mut work = Vec::new();
for i in 0..10 {
work.push((i.to_string(), multiply_async(i, i)));
}
for (label, res) in LabelPendingTaskIterator(work) {
println!("Finished task {label} -> {res}");
}
}
fn do_work(multiply: multiply_Scoped, myfn: myfn_Scoped) {
for i in 0..10 {
let x = multiply.call(i, i);
@ -41,17 +53,19 @@ fn main() {
let s = s.spawn();
do_work(multiply, myfn_fn);
s.join().unwrap();
let s = ServiceManager::new().mode(comrade::service::ServiceMode::Decay);
let s = myfn_init(s);
let s = multiply_init(s);
let s = take_time_init(s);
let s = s.spawn();
let x = myfn(55);
println!("myfn {x}");
batch_work();
// decoupled
let e = take_time_async(1500);
println!("This will run right after!");