Skip to content

Commit

Permalink
Fix CW tick events endless loop at shutdown
Browse files Browse the repository at this point in the history
Fixed an edge case with console wallet shutdown where the tick events send
loop will continue to send key events after the receiver part of the channel
has been closed.
  • Loading branch information
hansieodendaal committed Sep 27, 2021
1 parent 46268a9 commit 298ca6f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions applications/tari_console_wallet/src/utils/crossterm_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ impl CrosstermEvents {
) {
Ok(true) => {
if let Ok(CEvent::Key(key)) = event::read() {
if let Err(e) = tx.send(Event::Input(key)) {
warn!(target: LOG_TARGET, "Error sending Tick event on MPSC channel: {}", e);
if tx.send(Event::Input(key)).is_err() {
info!(target: LOG_TARGET, "Tick event channel shutting down");
// A send operation can only fail if the receiving end of a channel is disconnected.
break;
}
}
},
Expand All @@ -81,8 +83,10 @@ impl CrosstermEvents {
},
}
if last_tick.elapsed() >= config.tick_rate {
if let Err(e) = tx.send(Event::Tick) {
warn!(target: LOG_TARGET, "Error sending Tick event on MPSC channel: {}", e);
if tx.send(Event::Tick).is_err() {
info!(target: LOG_TARGET, "Tick event channel shutting down");
// A send operation can only fail if the receiving end of a channel is disconnected.
break;
}
last_tick = Instant::now();
}
Expand Down

0 comments on commit 298ca6f

Please sign in to comment.