init
This commit is contained in:
commit
5cb4facc48
8 changed files with 684 additions and 0 deletions
16
examples/functions.rs
Normal file
16
examples/functions.rs
Normal file
|
@ -0,0 +1,16 @@
|
|||
use std::time::Duration;
|
||||
|
||||
use comrade::rally;
|
||||
|
||||
fn main() {
|
||||
env_logger::init();
|
||||
|
||||
let items = vec![1, 2, 3, 4, 5];
|
||||
|
||||
let (input, output) = rally(items, |item: &_| {
|
||||
std::thread::sleep(Duration::from_millis(item * 100));
|
||||
return 0;
|
||||
});
|
||||
|
||||
println!("RALLY RESULTS: {input:?} -> {output:?}");
|
||||
}
|
29
examples/services.rs
Normal file
29
examples/services.rs
Normal file
|
@ -0,0 +1,29 @@
|
|||
use std::time::Duration;
|
||||
|
||||
use comrade::service::ServiceManager;
|
||||
|
||||
fn main() {
|
||||
env_logger::init();
|
||||
|
||||
log::info!("Running services example");
|
||||
|
||||
// persistent background services
|
||||
let mut s = ServiceManager::new();
|
||||
|
||||
s.register("myservice", |_| {
|
||||
let mut c = 0;
|
||||
loop {
|
||||
// ...
|
||||
println!("I am doing something!");
|
||||
std::thread::sleep(Duration::from_secs(1));
|
||||
c += 1;
|
||||
if c == 3 {
|
||||
panic!("Oh no!");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
let st = s.spawn();
|
||||
|
||||
st.join().unwrap();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue