promised fn

This commit is contained in:
JMARyA 2025-03-07 21:20:25 +01:00
parent e3393f1e09
commit 0c190df5d7
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
4 changed files with 39 additions and 1 deletions

View file

@ -1,3 +1,5 @@
use std::time::Duration;
use comrade::{
job::{JobDispatcher, JobOrder},
service::ServiceManager,
@ -5,6 +7,11 @@ use comrade::{
};
use crossbeam::channel::Receiver;
#[worker]
pub fn take_time(i: i32) {
std::thread::sleep(Duration::from_millis(i as u64));
}
#[worker]
pub fn myfn(i: i32) -> i32 {
i * 2
@ -39,12 +46,19 @@ fn main() {
let s = ServiceManager::new().mode(comrade::service::ServiceMode::Decay);
let s = myfn_init(s);
let s = take_time_init(s);
let s = s.spawn();
let x = myfn(55);
println!("myfn {x}");
// decoupled
let e = take_time_async(1500);
println!("This will run right after!");
println!("the value is {}", e.wait());
myfn_shutdown();
take_time_shutdown();
s.join().unwrap();
}