29 lines
581 B
Rust
29 lines
581 B
Rust
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();
|
|
}
|