diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-12-20 00:34:22 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-20 00:34:22 +0100 |
commit | e924bbdf3606e83ff9eef3a8ed640c4ecc34444f (patch) | |
tree | 19847fac129a678c1e5efa5f3495c8414146fa22 /cli/tests/worker_with_top_level_await.ts | |
parent | 660f75e066226a635375b70225df165bcf759077 (diff) |
fix: TLA in web worker (#8809)
Implementors of `deno_core::JsRuntime` might want to do additional actions
during each turn of event loop, eg. `deno_runtime::Worker` polls inspector,
`deno_runtime::WebWorker` receives/dispatches messages from/to worker host.
Previously `JsRuntime::mod_evaluate` was implemented in such fashion that it
only polled `JsRuntime`'s event loop. This behavior turned out to be wrong
in the example of `WebWorker` which couldn't receive/dispatch messages because
its implementation of event loop was never called.
This commit rewrites "mod_evaluate" to return a handle to receiver that resolves
when module's promise resolves. It is now implementors responsibility to poll
event loop after calling `mod_evaluate`.
Diffstat (limited to 'cli/tests/worker_with_top_level_await.ts')
-rw-r--r-- | cli/tests/worker_with_top_level_await.ts | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/cli/tests/worker_with_top_level_await.ts b/cli/tests/worker_with_top_level_await.ts new file mode 100644 index 000000000..cf3418bf7 --- /dev/null +++ b/cli/tests/worker_with_top_level_await.ts @@ -0,0 +1,15 @@ +// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. + +import { serve } from "../../std/http/server.ts"; + +const server = serve({ port: 8080 }); + +self.onmessage = (e: MessageEvent) => { + console.log("TLA worker received message", e.data); +}; + +self.postMessage("hello"); + +for await (const _r of server) { + // pass +} |