Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Nießen <tniessen@tnie.de>2022-01-23 15:14:11 +0300
committerGitHub <noreply@github.com>2022-01-23 15:14:11 +0300
commit0e6db9c3b06214db5d0868a5296560f786d77c00 (patch)
tree613afb98a968f37ef4137304de82c4c5440bf104 /doc/api/cluster.md
parentc18ca140a12b543a3f970ef379f384ebd3297c3d (diff)
doc: modernize and simplify cluster example
PR-URL: https://github.com/nodejs/node/pull/41626 Reviewed-By: Mestery <mestery@protonmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Diffstat (limited to 'doc/api/cluster.md')
-rw-r--r--doc/api/cluster.md20
1 files changed, 4 insertions, 16 deletions
diff --git a/doc/api/cluster.md b/doc/api/cluster.md
index 5dfd8116dc5..10af5fa20a1 100644
--- a/doc/api/cluster.md
+++ b/doc/api/cluster.md
@@ -1074,29 +1074,17 @@ list happens before the last `'disconnect'` or `'exit'` event is emitted.
```mjs
import cluster from 'cluster';
-// Go through all workers
-function eachWorker(callback) {
- for (const id in cluster.workers) {
- callback(cluster.workers[id]);
- }
-}
-eachWorker((worker) => {
+for (const worker of Object.values(cluster.workers)) {
worker.send('big announcement to all workers');
-});
+}
```
```cjs
const cluster = require('cluster');
-// Go through all workers
-function eachWorker(callback) {
- for (const id in cluster.workers) {
- callback(cluster.workers[id]);
- }
-}
-eachWorker((worker) => {
+for (const worker of Object.values(cluster.workers)) {
worker.send('big announcement to all workers');
-});
+}
```
Using the worker's unique id is the easiest way to locate the worker.