Fix wait_for_signal_and_error on win (#1811)

This commit is contained in:
Jon Häggblad
2022-11-29 09:43:08 +01:00
committed by GitHub
parent 822a3b70b7
commit 89b35c1483
3 changed files with 20 additions and 7 deletions
+1 -2
View File
@@ -38,8 +38,7 @@ use log::*;
use nymsphinx::addressing::clients::Recipient;
use nymsphinx::addressing::nodes::NodeIdentity;
use tap::TapFallible;
use task::signal::wait_for_signal_and_error;
use task::{ShutdownListener, ShutdownNotifier};
use task::{wait_for_signal_and_error, ShutdownListener, ShutdownNotifier};
pub mod config;
+1 -1
View File
@@ -5,4 +5,4 @@ pub mod shutdown;
pub mod signal;
pub use shutdown::{ShutdownListener, ShutdownNotifier};
pub use signal::wait_for_signal;
pub use signal::{wait_for_signal, wait_for_signal_and_error};
+18 -4
View File
@@ -1,3 +1,5 @@
use crate::{shutdown::SentError, ShutdownNotifier};
#[cfg(unix)]
pub async fn wait_for_signal() {
use tokio::signal::unix::{signal, SignalKind};
@@ -17,10 +19,17 @@ pub async fn wait_for_signal() {
}
}
#[cfg(not(unix))]
pub async fn wait_for_signal() {
tokio::select! {
_ = tokio::signal::ctrl_c() => {
log::info!("Received SIGINT");
},
}
}
#[cfg(unix)]
pub async fn wait_for_signal_and_error(
shutdown: &mut crate::ShutdownNotifier,
) -> Result<(), crate::shutdown::SentError> {
pub async fn wait_for_signal_and_error(shutdown: &mut ShutdownNotifier) -> Result<(), SentError> {
use tokio::signal::unix::{signal, SignalKind};
let mut sigterm = signal(SignalKind::terminate()).expect("Failed to setup SIGTERM channel");
@@ -47,10 +56,15 @@ pub async fn wait_for_signal_and_error(
}
#[cfg(not(unix))]
pub async fn wait_for_signal() {
pub async fn wait_for_signal_and_error(shutdown: &mut ShutdownNotifier) -> Result<(), SentError> {
tokio::select! {
_ = tokio::signal::ctrl_c() => {
log::info!("Received SIGINT");
Ok(())
},
Some(msg) = shutdown.wait_for_error() => {
log::info!("Task error: {:?}", msg);
Err(msg)
}
}
}