From a1d06dab881af05d2127f807ffbf861f943f1d1f Mon Sep 17 00:00:00 2001 From: Ben Bangert Date: Tue, 13 Feb 2018 15:08:30 -0800 Subject: [PATCH] feat: drain pending notifications from the client rx queue Closes #1133 --- autopush_rs/src/client.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/autopush_rs/src/client.rs b/autopush_rs/src/client.rs index a1615755..afb51027 100644 --- a/autopush_rs/src/client.rs +++ b/autopush_rs/src/client.rs @@ -712,7 +712,7 @@ where pub fn shutdown(&mut self) { // If we made it past hello, do more cleanup - let webpush = match self.webpush.take() { + let mut webpush = match self.webpush.take() { Some(webpush) => webpush, None => return }; @@ -730,6 +730,19 @@ where .send() .ok(); + // If there's any notifications in the queue, move them to our unacked direct notifs + webpush.rx.close(); + let remaining = webpush.rx.wait(); + for msg in remaining { + match msg { + Ok(ServerNotification::CheckStorage) => continue, + Ok(ServerNotification::Notification(notif)) => { + webpush.unacked_direct_notifs.push(notif.clone()); + } + Err(_) => continue, + } + } + // If there's direct unack'd messages, they need to be saved out without blocking // here self.srv.disconnet_client(&webpush.uaid);