mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
refactor: use new poll methods from JsRuntime (#21302)
This commit is contained in:
parent
a4ec7dfae0
commit
550a24ad0e
2 changed files with 31 additions and 8 deletions
|
@ -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<Result<(), AnyError>> {
|
||||
// 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
|
||||
};
|
||||
|
|
|
@ -603,14 +603,26 @@ impl MainWorker {
|
|||
cx: &mut Context,
|
||||
wait_for_inspector: bool,
|
||||
) -> Poll<Result<(), AnyError>> {
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue