#actix #daemon

actix-daemon-utils

Daemon Utilities by actix

8 unstable releases (3 breaking)

0.4.2 Oct 26, 2020
0.4.1 Sep 12, 2020
0.3.1 Jul 27, 2020
0.3.0 Mar 11, 2020
0.1.0 Feb 12, 2020

#171 in Asynchronous

Download history 162/week @ 2020-11-07 116/week @ 2020-11-14 132/week @ 2020-11-21 128/week @ 2020-11-28 161/week @ 2020-12-05 238/week @ 2020-12-12 220/week @ 2020-12-19 6/week @ 2020-12-26 163/week @ 2021-01-02 156/week @ 2021-01-09 176/week @ 2021-01-16 189/week @ 2021-01-23 159/week @ 2021-01-30 144/week @ 2021-02-06 267/week @ 2021-02-13 182/week @ 2021-02-20

680 downloads per month

MIT/Apache

10KB
214 lines

actix-daemon-utils

Daemon Utilities by actix.

Documentation

Features

  • Graceful Stop by singals(hangup, interrupt, quit or terminate)
  • Loop daemon(looper or delayer)

Examples

use actix_daemon_utils::{
    actix::{
        prelude::*,
        System,
    },
    graceful_stop::{GracefulStop},
    looper::{Looper, Task},
};
use std::time::Duration;

struct MyActor { msg: String, seconds: u64 }

impl Actor for MyActor {
    type Context = Context<Self>;
}

impl Handler<Task> for MyActor {
    type Result = Option<std::time::Duration>;

    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 = System::new("main");
    let graceful_stop = GracefulStop::new();
    let actor1 = MyActor { msg: "x".to_string(), seconds: 1 }.start();
    let actor2 = MyActor { msg: "y".to_string(), seconds: 3 }.start();
    let looper1 = Looper::new(actor1.recipient(), graceful_stop.clone_system_terminator()).start();
    let looper2 = Looper::new(actor2.recipient(), graceful_stop.clone_system_terminator()).start();
    graceful_stop
        .subscribe(looper1.recipient())
        .subscribe(looper2.recipient())
        .start();

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

Dependencies

~5.5MB
~103K SLoC