From 4a17c930882c5765e5fdedb50b6493469f61e32d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 12 Dec 2022 15:33:30 +0100 Subject: feat: add `--inspect-wait` flag (#17001) This commit adds new "--inspect-wait" flag which works similarly to "--inspect-brk" in that it waits for inspector session to be established before running code. However it doesn't break on the first statement of user code, but instead runs it as soon as a session is established. --- core/inspector.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'core') diff --git a/core/inspector.rs b/core/inspector.rs index 8a9136091..b9a5908ed 100644 --- a/core/inspector.rs +++ b/core/inspector.rs @@ -347,6 +347,23 @@ impl JsRuntimeInspector { } } + /// This function blocks the thread until at least one inspector client has + /// established a websocket connection. + pub fn wait_for_session(&mut self) { + loop { + match self.sessions.get_mut().established.iter_mut().next() { + Some(_session) => { + self.flags.get_mut().waiting_for_session = false; + break; + } + None => { + self.flags.get_mut().waiting_for_session = true; + let _ = self.poll_sessions(None).unwrap(); + } + }; + } + } + /// This function blocks the thread until at least one inspector client has /// established a websocket connection. /// -- cgit v1.2.3