Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING: make Worker.deno unstable (#5128)
This commit makes "Worker.deno" option unstable. Added new manual entry "docs/runtime/workers.md". Removed stale workers tests.
- Loading branch information
1 parent
2b66b8a
commit aca21da
Showing
13 changed files
with
60 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
## Workers | ||
|
||
Deno supports | ||
[`Web Worker API`](https://developer.mozilla.org/en-US/docs/Web/API/Worker/Worker). | ||
|
||
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 new worker: | ||
|
||
```ts | ||
// Good | ||
new Worker("./worker.js", { type: "module" }); | ||
|
||
// Bad | ||
new Worker("./worker.js"); | ||
new Worker("./worker.js", { type: "classic" }); | ||
``` | ||
|
||
### Using Deno in worker | ||
|
||
**UNSTABLE**: This feature is unstable and requires `--unstable` flag | ||
|
||
By default `Deno` namespace is not available in worker scope. | ||
|
||
To add `Deno` namespace pass `deno: true` option when creating new worker: | ||
|
||
```ts | ||
// main.js | ||
const worker = new Worker("./worker.js", { type: "module", deno: true }); | ||
worker.postMessage({ filename: "./log.txt" }); | ||
|
||
// worker.js | ||
self.onmessage = async (e) => { | ||
const { filename } = e.data; | ||
const text = await Deno.readTextFile(filename); | ||
console.log(text); | ||
self.close(); | ||
}; | ||
|
||
// log.txt | ||
hello world | ||
``` | ||
|
||
```shell | ||
$ deno run --allow-read --unstable main.js | ||
hello world | ||
``` | ||
|
||
When `Deno` namespace is available in worker scope; the worker inherits parent | ||
process permissions (the ones specified using `--allow-*` flags). | ||
|
||
We intend to make permissions configurable for workers. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters