From 135053486c4bd112ebd7d0b25c94a8dd346472e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 14 Oct 2020 14:04:09 +0200 Subject: fix: top-level-await module execution (#7946) This commit changes implementation of top-level-await in "deno_core". Previously promise returned from module evaluation was not awaited, leading to out-of-order execution of modules that have TLA. It's been fixed by changing "JsRuntime::mod_evaluate" to be an async function that resolves when the promise returned from module evaluation also resolves. When waiting for promise resolution event loop is polled repeatedly, until there are no more dynamic imports or pending ops. --- cli/ops/worker_host.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'cli/ops') diff --git a/cli/ops/worker_host.rs b/cli/ops/worker_host.rs index 8ebf8b9e6..ad915f7f7 100644 --- a/cli/ops/worker_host.rs +++ b/cli/ops/worker_host.rs @@ -153,9 +153,15 @@ fn run_worker_thread( rt.block_on(load_future) }; - if let Err(e) = result { - let mut sender = worker.internal_channels.sender.clone(); + let mut sender = worker.internal_channels.sender.clone(); + // If sender is closed it means that worker has already been closed from + // within using "globalThis.close()" + if sender.is_closed() { + return; + } + + if let Err(e) = result { sender .try_send(WorkerEvent::TerminalError(e)) .expect("Failed to post message to host"); -- cgit v1.2.3