Skip to content

Commit

Permalink
Fix lack of graceful shutdown for notification task
Browse files Browse the repository at this point in the history
  • Loading branch information
TTWNO committed Mar 6, 2024
1 parent efd02b7 commit 9fc9cd5
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions odilia/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,23 @@ use odilia_notify::listen_to_dbus_notifications;
use ssip_client_async::Priority;

use atspi_common::events::{document, object};
async fn notifications_monitor(state: Arc<ScreenReaderState>) -> eyre::Result<()> {
async fn notifications_monitor(
state: Arc<ScreenReaderState>,
shutdown_rx: &mut broadcast::Receiver<i32>,
) -> eyre::Result<()> {

Check warning on line 37 in odilia/src/main.rs

View check run for this annotation

Codecov / codecov/patch

odilia/src/main.rs#L34-L37

Added lines #L34 - L37 were not covered by tests
let mut stream = listen_to_dbus_notifications().await?;
while let Some(notification) = stream.next().await {
let notification_message =
loop {
tokio::select! {
Some(notification) = stream.next() => {

Check warning on line 41 in odilia/src/main.rs

View check run for this annotation

Codecov / codecov/patch

odilia/src/main.rs#L39-L41

Added lines #L39 - L41 were not covered by tests
let notification_message =
format!("new notification: {}, {}.", notification.title, notification.body);
state.say(Priority::Important, notification_message).await;
state.say(Priority::Important, notification_message).await;
},
_ = shutdown_rx.recv() => {
tracing::debug!("Shutting down notification task.");

Check warning on line 47 in odilia/src/main.rs

View check run for this annotation

Codecov / codecov/patch

odilia/src/main.rs#L47

Added line #L47 was not covered by tests
break;
},
}

Check warning on line 50 in odilia/src/main.rs

View check run for this annotation

Codecov / codecov/patch

odilia/src/main.rs#L50

Added line #L50 was not covered by tests
}
Ok(())
}
Expand Down Expand Up @@ -117,9 +128,10 @@ async fn main() -> eyre::Result<()> {
&mut shutdown_rx_odilia_proc_recv,
)
.map(|r| r.wrap_err("Could not process Odilia event"));
let signal_receiver = sigterm_signal_watcher(shutdown_tx)
let mut shutdown_rx_notif = shutdown_tx.subscribe();
let notification_task = notifications_monitor(Arc::clone(&state), &mut shutdown_rx_notif)

Check warning on line 132 in odilia/src/main.rs

View check run for this annotation

Codecov / codecov/patch

odilia/src/main.rs#L131-L132

Added lines #L131 - L132 were not covered by tests
.map(|r| r.wrap_err("Could not process signal shutdown."));
let notification_task = notifications_monitor(Arc::clone(&state))
let signal_receiver = sigterm_signal_watcher(shutdown_tx)

Check warning on line 134 in odilia/src/main.rs

View check run for this annotation

Codecov / codecov/patch

odilia/src/main.rs#L134

Added line #L134 was not covered by tests
.map(|r| r.wrap_err("Could not process signal shutdown."));

tokio::try_join!(
Expand Down

0 comments on commit 9fc9cd5

Please sign in to comment.