main: Add wait_signal function
Moving the signal handler setup and wait to a separate function will allow us to eventually create platform-specific implementations. Windows doesn't have SIGINT/SIGTERM, so we will need different logic if we ever want to support that OS.dev/ci
parent
ee8ed0c644
commit
cef128d1ef
15
src/main.rs
15
src/main.rs
|
@ -21,18 +21,23 @@ async fn main() {
|
||||||
config::load_config(std::env::var("MQTTMARIONETTE_CONFIG").ok())
|
config::load_config(std::env::var("MQTTMARIONETTE_CONFIG").ok())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let mut sig_term = unix::signal(SignalKind::terminate()).unwrap();
|
|
||||||
let mut sig_int = unix::signal(SignalKind::interrupt()).unwrap();
|
|
||||||
|
|
||||||
let task = tokio::spawn(async move {
|
let task = tokio::spawn(async move {
|
||||||
let session = Session::begin(config).await.unwrap();
|
let session = Session::begin(config).await.unwrap();
|
||||||
session.run().await;
|
session.run().await;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
wait_signal().await;
|
||||||
|
|
||||||
|
task.abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
async fn wait_signal() {
|
||||||
|
let mut sig_term = unix::signal(SignalKind::terminate()).unwrap();
|
||||||
|
let mut sig_int = unix::signal(SignalKind::interrupt()).unwrap();
|
||||||
|
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
_ = sig_term.recv() => info!("Received SIGTERM"),
|
_ = sig_term.recv() => info!("Received SIGTERM"),
|
||||||
_ = sig_int.recv() => info!("Received SIGINT"),
|
_ = sig_int.recv() => info!("Received SIGINT"),
|
||||||
};
|
};
|
||||||
|
|
||||||
task.abort();
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue