From 550a24ad0e3c3e7a2e344079fe4e16b3ab7c170b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 27 Nov 2023 00:09:04 +0100 Subject: [PATCH] refactor: use new poll methods from JsRuntime (#21302) --- runtime/web_worker.rs | 23 +++++++++++++++++------ runtime/worker.rs | 16 ++++++++++++++-- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs index 29b6aa3709..9293fce17d 100644 --- a/runtime/web_worker.rs +++ b/runtime/web_worker.rs @@ -33,6 +33,7 @@ use deno_core::ModuleId; use deno_core::ModuleLoader; use deno_core::ModuleSpecifier; use deno_core::OpMetricsSummaryTracker; +use deno_core::PollEventLoopOptions; use deno_core::RuntimeOptions; use deno_core::SharedArrayBufferStore; use deno_core::Snapshot; @@ -711,6 +712,11 @@ impl WebWorker { id: ModuleId, ) -> Result<(), AnyError> { let mut receiver = self.js_runtime.mod_evaluate(id); + let poll_options = PollEventLoopOptions { + wait_for_inspector: false, + ..Default::default() + }; + tokio::select! { biased; @@ -722,7 +728,7 @@ impl WebWorker { maybe_result.unwrap_or(Ok(())) } - event_loop_result = self.run_event_loop(false) => { + event_loop_result = self.run_event_loop(poll_options) => { if self.internal_handle.is_terminated() { return Ok(()); } @@ -736,7 +742,7 @@ impl WebWorker { fn poll_event_loop( &mut self, cx: &mut Context, - wait_for_inspector: bool, + poll_options: PollEventLoopOptions, ) -> Poll> { // If awakened because we are terminating, just return Ok if self.internal_handle.terminate_if_needed() { @@ -745,7 +751,7 @@ impl WebWorker { self.internal_handle.terminate_waker.register(cx.waker()); - match self.js_runtime.poll_event_loop(cx, wait_for_inspector) { + match self.js_runtime.poll_event_loop2(cx, poll_options) { Poll::Ready(r) => { // If js ended because we are terminating, just return Ok if self.internal_handle.terminate_if_needed() { @@ -773,9 +779,9 @@ impl WebWorker { pub async fn run_event_loop( &mut self, - wait_for_inspector: bool, + poll_options: PollEventLoopOptions, ) -> Result<(), AnyError> { - poll_fn(|cx| self.poll_event_loop(cx, wait_for_inspector)).await + poll_fn(|cx| self.poll_event_loop(cx, poll_options)).await } // Starts polling for messages from worker host from JavaScript. @@ -851,7 +857,12 @@ pub fn run_web_worker( } let result = if result.is_ok() { - worker.run_event_loop(true).await + worker + .run_event_loop(PollEventLoopOptions { + wait_for_inspector: true, + ..Default::default() + }) + .await } else { result }; diff --git a/runtime/worker.rs b/runtime/worker.rs index c60e189f78..667644dc8b 100644 --- a/runtime/worker.rs +++ b/runtime/worker.rs @@ -603,14 +603,26 @@ impl MainWorker { cx: &mut Context, wait_for_inspector: bool, ) -> Poll> { - self.js_runtime.poll_event_loop(cx, wait_for_inspector) + self.js_runtime.poll_event_loop2( + cx, + deno_core::PollEventLoopOptions { + wait_for_inspector, + ..Default::default() + }, + ) } pub async fn run_event_loop( &mut self, wait_for_inspector: bool, ) -> Result<(), AnyError> { - self.js_runtime.run_event_loop(wait_for_inspector).await + self + .js_runtime + .run_event_loop2(deno_core::PollEventLoopOptions { + wait_for_inspector, + ..Default::default() + }) + .await } /// Return exit code set by the executed code (either in main worker