add monoio::signal::ctrl_c() support under feature "signal"
yngrtc opened this issue · 2 comments
yngrtc commented
Is your feature request related to a problem? Please describe.
I am trying to use tokio::signal::ctrl_c() in monoio runtime, but got the error
thread 'main' panicked at 'there is no reactor running, must be called from the context of a Tokio 1.x runtime', /home/yliu/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.26.0/src/signal/unix.rs:499:5
Describe the solution you'd like
add monoio::signal::ctrl_c() support in feature "signal"
Describe alternatives you've considered
no alternative
Additional context
N/A
yngrtc commented
actually I found a workaround with sync
feature enabled in monoio
let (tx, rx) = futures::channel::oneshot::channel();
std::thread::spawn(move || {
let mut tx = Some(tx);
ctrlc::set_handler(move || {
if let Some(tx) = tx.take() {
let _ = tx.send(());
}
})
.expect("Error setting Ctrl-C handler");
});
let _ = rx.await;
SteveLauC commented
I made this toy crate https://github.com/SteveLauC/async_signal_handler, it works in my use case. Currently, only UNIX platforms are supported.