Skip to content

Commit 1697604

Browse files
Trottaddaleax
authored andcommitted
doc,worker: revise worker_threads.md
Rewrite worker_threads introductory material focusing on simpler and shorter sentences. PR-URL: #25402 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent a6df727 commit 1697604

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

doc/api/worker_threads.md

+11-13
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,20 @@
44

55
> Stability: 1 - Experimental
66
7-
The `worker` module provides a way to create multiple environments running
8-
on independent threads, and to create message channels between them. It
9-
can be accessed using:
7+
The `worker_threads` module enables the use of threads with message channels
8+
between them. To access it:
109

1110
```js
1211
const worker = require('worker_threads');
1312
```
1413

15-
Workers are useful for performing CPU-intensive JavaScript operations; do not
16-
use them for I/O, since Node.js’s built-in mechanisms for performing operations
17-
asynchronously already treat it more efficiently than Worker threads can.
14+
Workers (threads) are useful for performing CPU-intensive JavaScript operations.
15+
They will not help much with I/O-intensive work. Node.js’s built-in asynchronous
16+
I/O operations are more efficient than Workers can be.
1817

19-
Workers, unlike child processes or when using the `cluster` module, can also
20-
share memory efficiently by transferring `ArrayBuffer` instances or sharing
21-
`SharedArrayBuffer` instances between them.
18+
Unlike `child_process` or `cluster`, `worker_threads` can share memory. They do
19+
so by transferring `ArrayBuffer` instances or sharing `SharedArrayBuffer`
20+
instances.
2221

2322
```js
2423
const {
@@ -46,10 +45,9 @@ if (isMainThread) {
4645
}
4746
```
4847

49-
Note that this example spawns a Worker thread for each `parse` call.
50-
In practice, it is strongly recommended to use a pool of Workers for these
51-
kinds of tasks, since the overhead of creating Workers would likely exceed the
52-
benefit of handing the work off to it.
48+
The above example spawns a Worker thread for each `parse()` call. In actual
49+
practice, use a pool of Workers instead for these kinds of tasks. Otherwise, the
50+
overhead of creating Workers would likely exceed their benefit.
5351

5452
## worker.isMainThread
5553
<!-- YAML

0 commit comments

Comments
 (0)