Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b951764

Browse filesBrowse 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
Copy full SHA for b951764

File tree

Expand file treeCollapse file tree

1 file changed

+4
-16
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+4
-16
lines changed
Open diff view settings
Collapse file

‎doc/api/cluster.md‎

Copy file name to clipboardExpand all lines: doc/api/cluster.md
+4-16Lines changed: 4 additions & 16 deletions
  • Display the source diff
  • Display the rich diff
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.