diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2022-12-16 20:12:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-16 20:12:06 +0100 |
commit | a202e38316886a5a9828c4dec9f126ec44568bac (patch) | |
tree | f9397510d1bcbaa36cc24ffb88411e76cd169bcf /core/inspector.rs | |
parent | ff71ef81751da1babdc4f9d1df5c279e7c64f305 (diff) |
refactor(core): allow to listen for notifications in LocalInspectorSession (#17040)
Diffstat (limited to 'core/inspector.rs')
-rw-r--r-- | core/inspector.rs | 15 |
1 files changed, 9 insertions, 6 deletions
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<InspectorMsg>, response_tx_map: HashMap<i32, oneshot::Sender<serde_json::Value>>, next_message_id: i32, - notification_queue: Vec<Value>, + notification_tx: UnboundedSender<Value>, + notification_rx: Option<UnboundedReceiver<Value>>, } 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::<Value>(); 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<Value> { - self.notification_queue.split_off(0) + pub fn take_notification_rx(&mut self) -> UnboundedReceiver<Value> { + self.notification_rx.take().unwrap() } pub async fn post_message<T: serde::Serialize>( @@ -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); } } } |