[][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 you want to unregister all signal which register to a Signals, just drop it, it will unregister all signals.

Notes:

for now you can't re-register some signals after drops a Signals, it may change in the future.

Methods

impl Signals[src]

pub fn new<I, S>(signals: I) -> Result<Self> where
    I: IntoIterator<Item = S>,
    S: Borrow<c_int>, 
[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();
    let signal = signal.unwrap();

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

pub fn add_signal(&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();
    let signal = signal.unwrap();

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

Trait Implementations

impl Drop for Signals[src]

impl Stream for Signals[src]

type Item = Result<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.

impl<S, T, E> TryStream for S where
    S: Stream<Item = Result<T, E>> + ?Sized
[src]

type Ok = T

The type of successful values yielded by this future

type Error = E

The type of failures yielded by this future

impl<S> TryStreamExt for S where
    S: TryStream + ?Sized
[src]