File tree Expand file tree Collapse file tree 1 file changed +4
-16
lines changed
Expand file tree Collapse file tree 1 file changed +4
-16
lines changed Original file line number Diff line number Diff line change @@ -1074,29 +1074,17 @@ list happens before the last `'disconnect'` or `'exit'` event is emitted.
10741074```mjs
10751075import 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
10891083const 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
11021090Using the worker's unique id is the easiest way to locate the worker.
You can’t perform that action at this time.
0 commit comments