gent-daemon 0.1.2

Local daemon, storage and synchronization for Gent chat clusters.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//! Register process signals at the supervisor that owns shutdown ordering.
use std::{future::Future, io};
use tokio::signal::unix::{SignalKind, signal};

/// Register both signals before starting services, then wait for a signal or
/// the caller's cooperative shutdown. Registration errors fail startup.
pub fn with_signals(shutdown: impl Future<Output = ()>) -> io::Result<impl Future<Output = ()>> {
    let mut interrupt = signal(SignalKind::interrupt())?;
    let mut terminate = signal(SignalKind::terminate())?;
    Ok(async move {
        tokio::select! {
            _ = shutdown => {},
            _ = interrupt.recv() => {},
            _ = terminate.recv() => {},
        }
    })
}