]> git.lizzy.rs Git - dragonblocks-rs.git/blob - src/quit.rs
Create LICENSE
[dragonblocks-rs.git] / src / quit.rs
1 use log::*;
2 use tokio::sync::{broadcast, mpsc};
3
4 #[derive(Debug, Clone)]
5 pub struct Quit {
6     signal: broadcast::Sender<()>,
7
8     #[allow(unused)]
9     confirm: mpsc::Sender<()>,
10 }
11
12 impl Quit {
13     pub fn new() -> (Self, mpsc::Receiver<()>) {
14         let (confirm, confirm_recv) = mpsc::channel(1);
15         let (signal, _) = broadcast::channel(1);
16
17         (Self { confirm, signal }, confirm_recv)
18     }
19
20     pub fn quit(&self) {
21         info!("Shutting down");
22         self.signal.send(()).unwrap();
23     }
24
25     pub fn subscribe(&self) -> broadcast::Receiver<()> {
26         self.signal.subscribe()
27     }
28 }