[][src]Struct async_signals::Signals

pub struct Signals { /* fields omitted */ }

Handle unix signal like signal_hook::iterator::Signals, receive signals with futures::stream::Stream.

If multi Signals register a same signal, all of them will receive the signal.

If you drop all Signals which handle a signal like SIGINT, when process receive this signal, will use system default handler.

Notes:

You can't handle SIGKILL or SIGSTOP.

Methods

impl Signals[src]

pub fn new<I: IntoIterator<Item = c_int>>(signals: I) -> Result<Signals>[src]

Creates the Signals structure, all signals will be registered.

Examples

use async_signals::Signals;
use futures_util::StreamExt;
use nix::sys;
use nix::unistd;

#[async_std::main]
async fn main() {
    let mut signals = Signals::new(vec![libc::SIGINT]).unwrap();

    let pid = unistd::getpid();
    sys::signal::kill(pid, Some(sys::signal::SIGINT)).unwrap();

    let signal = signals.next().await.unwrap();

    assert_eq!(signal, libc::SIGINT);
}

pub fn add_signal(&mut self, signal: c_int) -> Result<()>[src]

Registers another signal to a created Signals.

Examples

use async_signals::Signals;
use futures_util::StreamExt;
use nix::sys;
use nix::unistd;

#[async_std::main]
async fn main() {
    let mut signals = Signals::new(vec![libc::SIGHUP]).unwrap();

    signals.add_signal(libc::SIGINT).unwrap();

    let pid = unistd::getpid();
    sys::signal::kill(pid, Some(sys::signal::SIGINT)).unwrap();

    let signal = signals.next().await.unwrap();

    assert_eq!(signal, libc::SIGINT);
}

Trait Implementations

impl Debug for Signals[src]

impl Drop for Signals[src]

impl Stream for Signals[src]

type Item = c_int

Values yielded by the stream.

Auto Trait Implementations

impl RefUnwindSafe for Signals

impl Send for Signals

impl Sync for Signals

impl Unpin for Signals

impl UnwindSafe for Signals

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> StreamExt for T where
    T: Stream + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.