Skip to content

Signal stream library for rust

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

Xudong-Huang/may_signal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

may_signal

Signal handling library

You can use this library to wait for a signal in coroutine context without blocking the thread.

Build Status

Documentation

Usage

First, add this to your Cargo.toml:

[dependencies]
may_signal = "0.1"

Next you can use the API directly:

#[macro_use]
extern crate may;
extern crate may_signal;

fn main() {
    let s = may_signal::ctrl_c();
    for _ in s.iter().take(3) {
        println!("CTRL_C pressed!");
    }

    join!(
        {
            let s = may_signal::ctrl_c();
            for _ in s.iter().take(3) {
                println!("CTRL_C pressed! in coroutine 0");
            }
        },
        {
            let s = may_signal::ctrl_c();
            for _ in s.iter().take(4) {
                println!("CTRL_C pressed! in coroutine 1");
            }
        }
    );

    #[cfg(unix)]
    {
        let sig_int = may_signal::Signal::new(may_signal::unix::SIGINT).unwrap();
        let sig_trm = may_signal::Signal::new(may_signal::unix::SIGTERM).unwrap();
        for _ in 0..3 {
            select!(
                _ = sig_int.recv().unwrap() => println!("SIGINT received"),
                _ = sig_trm.recv().unwrap() => println!("SIGTRM received")
            );
        }
    }
}

License

This project is licensed under either of

at your option.

About

Signal stream library for rust

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages