This commit is contained in:
JMARyA 2025-03-07 04:33:35 +01:00
commit 5cb4facc48
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
8 changed files with 684 additions and 0 deletions

29
examples/services.rs Normal file
View 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();
}