1
0
mirror of https://github.com/romanz/electrs.git synced 2024-11-19 09:54:09 +01:00

There should be one (and only one) signal handler in electrs

This commit is contained in:
Roman Zeyde 2021-10-03 21:15:22 +03:00
parent b51d2af65b
commit 239e4658af
2 changed files with 6 additions and 4 deletions

View File

@ -145,6 +145,10 @@ impl Rpc {
})
}
pub(crate) fn signal(&self) -> &Signal {
&self.signal
}
pub fn sync(&mut self) -> Result<()> {
self.tracker.sync(&self.daemon, self.signal.exit_flag())
}

View File

@ -15,7 +15,6 @@ use crate::{
config::Config,
daemon::rpc_connect,
electrum::{Client, Rpc},
signals::Signal,
thread::spawn,
};
@ -100,14 +99,13 @@ pub fn run(config: &Config, mut rpc: Rpc) -> Result<()> {
let (server_tx, server_rx) = unbounded();
spawn("accept_loop", || accept_loop(listener, server_tx)); // detach accepting thread
let signal = Signal::new();
let mut peers = HashMap::<usize, Peer>::new();
loop {
select! {
recv(signal.receiver()) -> result => {
recv(rpc.signal().receiver()) -> result => {
result.context("signal channel disconnected")?;
if signal.exit_flag().is_set() {
if rpc.signal().exit_flag().is_set() {
break;
}
},