Skip to content

Commit 5d9c83e

Browse files
tniessendanielleadams
authored andcommittedMar 14, 2022
doc: modernize and simplify cluster example
PR-URL: #41626 Reviewed-By: Mestery <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent dc854c4 commit 5d9c83e

File tree

1 file changed

+4
-16
lines changed

1 file changed

+4
-16
lines changed
 

‎doc/api/cluster.md

+4-16
Original file line numberDiff line numberDiff line change
@@ -1074,29 +1074,17 @@ list happens before the last `'disconnect'` or `'exit'` event is emitted.
10741074
```mjs
10751075
import cluster from 'cluster';
10761076

1077-
// Go through all workers
1078-
function eachWorker(callback) {
1079-
for (const id in cluster.workers) {
1080-
callback(cluster.workers[id]);
1081-
}
1082-
}
1083-
eachWorker((worker) => {
1077+
for (const worker of Object.values(cluster.workers)) {
10841078
worker.send('big announcement to all workers');
1085-
});
1079+
}
10861080
```
10871081

10881082
```cjs
10891083
const cluster = require('cluster');
10901084

1091-
// Go through all workers
1092-
function eachWorker(callback) {
1093-
for (const id in cluster.workers) {
1094-
callback(cluster.workers[id]);
1095-
}
1096-
}
1097-
eachWorker((worker) => {
1085+
for (const worker of Object.values(cluster.workers)) {
10981086
worker.send('big announcement to all workers');
1099-
});
1087+
}
11001088
```
11011089

11021090
Using the worker's unique id is the easiest way to locate the worker.

0 commit comments

Comments
 (0)
Please sign in to comment.