Skip to content

Commit b951764

Browse files
tniessenBethGriggs
authored andcommitted
doc: modernize and simplify cluster example
PR-URL: #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>
1 parent d33d189 commit b951764

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)