File tree 1 file changed +4
-16
lines changed
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.
1074
1074
``` mjs
1075
1075
import cluster from ' cluster' ;
1076
1076
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 )) {
1084
1078
worker .send (' big announcement to all workers' );
1085
- });
1079
+ }
1086
1080
```
1087
1081
1088
1082
``` cjs
1089
1083
const cluster = require (' cluster' );
1090
1084
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 )) {
1098
1086
worker .send (' big announcement to all workers' );
1099
- });
1087
+ }
1100
1088
```
1101
1089
1102
1090
Using 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