actix-daemon-utils

Daemon Utilities by actix.

Documentation

Features

Examples

```rust use actix::prelude::*; use actixdaemonutils::{ graceful_stop::{GracefulStop}, looper::{Looper, Task}, }; use std::time::Duration;

struct MyActor { msg: String, seconds: u64 }

impl Actor for MyActor { type Context = Context; }

impl Handler for MyActor { type Result = Option;

fn handle(&mut self, _msg: Task, _ctx: &mut Self::Context) -> Self::Result {
    println!("{}", self.msg);
    Some(Duration::from_secs(self.seconds))
}

}

fn main() { let sys = actix::System::new("main"); let gracefulstop = GracefulStop::new(); let actor1 = MyActor { msg: "x".tostring(), seconds: 1 }.start(); let actor2 = MyActor { msg: "y".tostring(), seconds: 3 }.start(); let looper1 = Looper::new(actor1.recipient(), gracefulstop.clonesystemterminator()).start(); let looper2 = Looper::new(actor2.recipient(), gracefulstop.clonesystemterminator()).start(); gracefulstop .subscribe(looper1.recipient()) .subscribe(looper2.recipient()) .start();

let _ = sys.run();
println!("main terminated");

} ```