✨ promised fn
This commit is contained in:
parent
e3393f1e09
commit
0c190df5d7
4 changed files with 39 additions and 1 deletions
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue