diff options
author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2021-03-04 12:19:47 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-04 13:19:47 +0100 |
commit | 0f2121355f65baa27b530ef286c8b4ca0009fabf (patch) | |
tree | 646725573df762eb09035dd7533e9d4d40280461 /cli/tests/workers/test.ts | |
parent | af7e02124fbec3cd3b2d17f6fa88682b826e455e (diff) |
fix(runtime/web_worker): Don't block self.onmessage with TLA (#9619)
This commit rewrites implementation of "JsRuntime::mod_evaluate".
Event loop is no longer polled automatically and users must manually
drive event loop forward after calling "mod_evaluate".
Co-authored-by: Nayeem Rahman <nayeemrmn99@gmail.com>
Co-authored-by: Bartek IwaĆczuk <biwanczuk@gmail.com>
Diffstat (limited to 'cli/tests/workers/test.ts')
-rw-r--r-- | cli/tests/workers/test.ts | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/cli/tests/workers/test.ts b/cli/tests/workers/test.ts index 0888e01db..f411e434f 100644 --- a/cli/tests/workers/test.ts +++ b/cli/tests/workers/test.ts @@ -675,3 +675,24 @@ Deno.test({ w.terminate(); }, }); + +Deno.test({ + name: "Worker with top-level-await", + fn: async function (): Promise<void> { + const result = deferred(); + const worker = new Worker( + new URL("worker_with_top_level_await.ts", import.meta.url).href, + { type: "module" }, + ); + worker.onmessage = (e): void => { + if (e.data == "ready") { + worker.postMessage("trigger worker handler"); + } else if (e.data == "triggered worker handler") { + result.resolve(); + } else { + result.reject(new Error("Handler didn't run during top-level delay.")); + } + }; + await result; + }, +}); |