summaryrefslogtreecommitdiff
path: root/docs/runtime/workers.md
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2020-06-09 13:33:52 +0100
committerGitHub <noreply@github.com>2020-06-09 14:33:52 +0200
commit44251ce8eaa0def807b9867f73ee23adfb539487 (patch)
treec5d54ca5aeb873fe948270149743c968e9a5efa5 /docs/runtime/workers.md
parent81a6f673ad48f15183575105016509e7743ff0ac (diff)
fix(cli/js/web/worker): Disable relative module specifiers (#5266)
Diffstat (limited to 'docs/runtime/workers.md')
-rw-r--r--docs/runtime/workers.md21
1 files changed, 15 insertions, 6 deletions
diff --git a/docs/runtime/workers.md b/docs/runtime/workers.md
index 110255b8b..019df7201 100644
--- a/docs/runtime/workers.md
+++ b/docs/runtime/workers.md
@@ -7,15 +7,21 @@ Workers can be used to run code on multiple threads. Each instance of `Worker`
is run on a separate thread, dedicated only to that worker.
Currently Deno supports only `module` type workers; thus it's essential to pass
-`type: "module"` option when creating a new worker:
+the `type: "module"` option when creating a new worker.
+
+Relative module specifiers are
+[not supported](https://github.com/denoland/deno/issues/5216) at the moment. You
+can instead use the `URL` contructor and `import.meta.url` to easily create a
+specifier for some nearby script.
```ts
// Good
-new Worker("./worker.js", { type: "module" });
+new Worker(new URL("worker.js", import.meta.url).href, { type: "module" });
// Bad
-new Worker("./worker.js");
-new Worker("./worker.js", { type: "classic" });
+new Worker(new URL("worker.js", import.meta.url).href);
+new Worker(new URL("worker.js", import.meta.url).href, { type: "classic" });
+new Worker("./worker.js", { type: "module" });
```
### Permissions
@@ -28,7 +34,7 @@ For workers using local modules; `--allow-read` permission is required:
**main.ts**
```ts
-new Worker("./worker.ts", { type: "module" });
+new Worker(new URL("worker.ts", import.meta.url).href, { type: "module" });
```
**worker.ts**
@@ -81,7 +87,10 @@ To add the `Deno` namespace pass `deno: true` option when creating new worker:
**main.js**
```ts
-const worker = new Worker("./worker.js", { type: "module", deno: true });
+const worker = new Worker(new URL("worker.js", import.meta.url).href, {
+ type: "module",
+ deno: true,
+});
worker.postMessage({ filename: "./log.txt" });
```