From a202e38316886a5a9828c4dec9f126ec44568bac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Fri, 16 Dec 2022 20:12:06 +0100 Subject: refactor(core): allow to listen for notifications in LocalInspectorSession (#17040) --- core/inspector.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'core') diff --git a/core/inspector.rs b/core/inspector.rs index b9a5908ed..0b04bf5f8 100644 --- a/core/inspector.rs +++ b/core/inspector.rs @@ -696,7 +696,8 @@ pub struct LocalInspectorSession { v8_session_rx: UnboundedReceiver, response_tx_map: HashMap>, next_message_id: i32, - notification_queue: Vec, + notification_tx: UnboundedSender, + notification_rx: Option>, } impl LocalInspectorSession { @@ -707,19 +708,20 @@ impl LocalInspectorSession { let response_tx_map = HashMap::new(); let next_message_id = 0; - let notification_queue = Vec::new(); + let (notification_tx, notification_rx) = mpsc::unbounded::(); Self { v8_session_tx, v8_session_rx, response_tx_map, next_message_id, - notification_queue, + notification_tx, + notification_rx: Some(notification_rx), } } - pub fn notifications(&mut self) -> Vec { - self.notification_queue.split_off(0) + pub fn take_notification_rx(&mut self) -> UnboundedReceiver { + self.notification_rx.take().unwrap() } pub async fn post_message( @@ -795,7 +797,8 @@ impl LocalInspectorSession { .unwrap(); } else { let message = serde_json::from_str(&inspector_msg.content).unwrap(); - self.notification_queue.push(message); + // Ignore if the receiver has been dropped. + let _ = self.notification_tx.unbounded_send(message); } } } -- cgit v1.2.3