summaryrefslogtreecommitdiff
path: root/cli/tests/subdir/nested_worker.js
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2020-02-11 10:04:59 +0100
committerGitHub <noreply@github.com>2020-02-11 10:04:59 +0100
commit79b3bc05d6de520f1df73face1744ae3d8be0bb8 (patch)
treef4c449efa67b88c767df52dd3ecec2246dded2e5 /cli/tests/subdir/nested_worker.js
parent81905a867ea3f942619229e330840d132c57a5da (diff)
workers: basic event loop (#3828)
* establish basic event loop for workers * make "self.close()" inside worker * remove "runWorkerMessageLoop() - instead manually call global function in Rust when message arrives. This is done in preparation for structured clone * refactor "WorkerChannel" and use distinct structs for internal and external channels; "WorkerChannelsInternal" and "WorkerHandle" * move "State.worker_channels_internal" to "Worker.internal_channels" * add "WorkerEvent" enum for child->host communication; currently "Message(Buf)" and "Error(ErrBox)" variants are supported * add tests for nested workers * add tests for worker throwing error on startup
Diffstat (limited to 'cli/tests/subdir/nested_worker.js')
-rw-r--r--cli/tests/subdir/nested_worker.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/cli/tests/subdir/nested_worker.js b/cli/tests/subdir/nested_worker.js
new file mode 100644
index 000000000..b0acd70d7
--- /dev/null
+++ b/cli/tests/subdir/nested_worker.js
@@ -0,0 +1,19 @@
+// Specifier should be resolved relative to current file
+const jsWorker = new Worker("./sibling_worker.js", {
+ type: "module",
+ name: "sibling"
+});
+
+jsWorker.onerror = _e => {
+ postMessage({ type: "error" });
+};
+
+jsWorker.onmessage = e => {
+ console.log("js worker on message");
+ postMessage({ type: "msg", text: e });
+ close();
+};
+
+onmessage = function(e) {
+ jsWorker.postMessage(e.data);
+};