@@ -108,12 +108,18 @@ responsibility to manage the worker pool for your application's needs.
108
108
109
109
110
110
## Class: Worker
111
+ <!-- YAML
112
+ added: v0.7.0
113
+ -->
111
114
112
115
A Worker object contains all public information and method about a worker.
113
116
In the master it can be obtained using ` cluster.workers ` . In a worker
114
117
it can be obtained using ` cluster.worker ` .
115
118
116
119
### Event: 'disconnect'
120
+ <!-- YAML
121
+ added: v0.7.7
122
+ -->
117
123
118
124
Similar to the ` cluster.on('disconnect') ` event, but specific to this worker.
119
125
@@ -124,12 +130,18 @@ cluster.fork().on('disconnect', () => {
124
130
```
125
131
126
132
### Event: 'error'
133
+ <!-- YAML
134
+ added: v0.7.3
135
+ -->
127
136
128
137
This event is the same as the one provided by [ ` child_process.fork() ` ] [ ] .
129
138
130
139
In a worker you can also use ` process.on('error') ` .
131
140
132
141
### Event: 'exit'
142
+ <!-- YAML
143
+ added: v0.11.2
144
+ -->
133
145
134
146
* ` code ` {Number} the exit code, if it exited normally.
135
147
* ` signal ` {String} the name of the signal (eg. ` 'SIGHUP' ` ) that caused
@@ -151,6 +163,9 @@ worker.on('exit', (code, signal) => {
151
163
```
152
164
153
165
### Event: 'listening'
166
+ <!-- YAML
167
+ added: v0.7.0
168
+ -->
154
169
155
170
* ` address ` {Object}
156
171
@@ -165,6 +180,9 @@ cluster.fork().on('listening', (address) => {
165
180
It is not emitted in the worker.
166
181
167
182
### Event: 'message'
183
+ <!-- YAML
184
+ added: v0.7.0
185
+ -->
168
186
169
187
* ` message ` {Object}
170
188
* ` handle ` {undefined|Object}
@@ -220,6 +238,9 @@ if (cluster.isMaster) {
220
238
```
221
239
222
240
### Event: 'online'
241
+ <!-- YAML
242
+ added: v0.7.0
243
+ -->
223
244
224
245
Similar to the ` cluster.on('online') ` event, but specific to this worker.
225
246
@@ -232,6 +253,9 @@ cluster.fork().on('online', () => {
232
253
It is not emitted in the worker.
233
254
234
255
### worker.disconnect()
256
+ <!-- YAML
257
+ added: v0.7.7
258
+ -->
235
259
236
260
In a worker, this function will close all servers, wait for the ` 'close' ` event on
237
261
those servers, and then disconnect the IPC channel.
@@ -293,6 +317,9 @@ if (cluster.isMaster) {
293
317
```
294
318
295
319
### worker.exitedAfterDisconnect
320
+ <!-- YAML
321
+ added: v6.0.0
322
+ -->
296
323
297
324
* {Boolean}
298
325
@@ -314,6 +341,9 @@ worker.kill();
314
341
```
315
342
316
343
### worker.id
344
+ <!-- YAML
345
+ added: v0.8.0
346
+ -->
317
347
318
348
* {Number}
319
349
@@ -324,17 +354,26 @@ While a worker is alive, this is the key that indexes it in
324
354
cluster.workers
325
355
326
356
### worker.isConnected()
357
+ <!-- YAML
358
+ added: v0.11.14
359
+ -->
327
360
328
361
This function returns ` true ` if the worker is connected to its master via its IPC
329
362
channel, ` false ` otherwise. A worker is connected to its master after it's been
330
363
created. It is disconnected after the ` 'disconnect' ` event is emitted.
331
364
332
365
### worker.isDead()
366
+ <!-- YAML
367
+ added: v0.11.14
368
+ -->
333
369
334
370
This function returns ` true ` if the worker's process has terminated (either
335
371
because of exiting or being signaled). Otherwise, it returns ` false ` .
336
372
337
373
### worker.kill([ signal='SIGTERM'] )
374
+ <!-- YAML
375
+ added: v0.9.12
376
+ -->
338
377
339
378
* ` signal ` {String} Name of the kill signal to send to the worker
340
379
process.
@@ -351,6 +390,9 @@ Note that in a worker, `process.kill()` exists, but it is not this function,
351
390
it is [ ` kill ` ] [ ] .
352
391
353
392
### worker.process
393
+ <!-- YAML
394
+ added: v0.7.0
395
+ -->
354
396
355
397
* {ChildProcess}
356
398
@@ -365,6 +407,9 @@ on `process` and `.exitedAfterDisconnect` is not `true`. This protects against
365
407
accidental disconnection.
366
408
367
409
### worker.send(message[ , sendHandle] [ , callback ] )
410
+ <!-- YAML
411
+ added: v0.7.0
412
+ -->
368
413
369
414
* ` message ` {Object}
370
415
* ` sendHandle ` {Handle}
@@ -394,6 +439,10 @@ if (cluster.isMaster) {
394
439
```
395
440
396
441
### worker.suicide
442
+ <!-- YAML
443
+ added: v0.7.0
444
+ deprecated: v6.0.0
445
+ -->
397
446
398
447
> Stability: 0 - Deprecated: Use [ ` worker.exitedAfterDisconnect ` ] [ ] instead.
399
448
@@ -420,6 +469,9 @@ This API only exists for backwards compatibility and will be removed in the
420
469
future.
421
470
422
471
## Event: 'disconnect'
472
+ <!-- YAML
473
+ added: v0.7.9
474
+ -->
423
475
424
476
* ` worker ` {cluster.Worker}
425
477
@@ -438,6 +490,9 @@ cluster.on('disconnect', (worker) => {
438
490
```
439
491
440
492
## Event: 'exit'
493
+ <!-- YAML
494
+ added: v0.7.9
495
+ -->
441
496
442
497
* ` worker ` {cluster.Worker}
443
498
* ` code ` {Number} the exit code, if it exited normally.
@@ -459,6 +514,9 @@ cluster.on('exit', (worker, code, signal) => {
459
514
See [ child_process event: 'exit'] [ ] .
460
515
461
516
## Event: 'fork'
517
+ <!-- YAML
518
+ added: v0.7.0
519
+ -->
462
520
463
521
* ` worker ` {cluster.Worker}
464
522
@@ -484,6 +542,9 @@ cluster.on('exit', (worker, code, signal) => {
484
542
```
485
543
486
544
## Event: 'listening'
545
+ <!-- YAML
546
+ added: v0.7.0
547
+ -->
487
548
488
549
* ` worker ` {cluster.Worker}
489
550
* ` address ` {Object}
@@ -538,6 +599,9 @@ cluster.on('message', function(worker, message, handle) {
538
599
```
539
600
540
601
## Event: 'online'
602
+ <!-- YAML
603
+ added: v0.7.0
604
+ -->
541
605
542
606
* ` worker ` {cluster.Worker}
543
607
@@ -553,6 +617,9 @@ cluster.on('online', (worker) => {
553
617
```
554
618
555
619
## Event: 'setup'
620
+ <!-- YAML
621
+ added: v0.7.1
622
+ -->
556
623
557
624
* ` settings ` {Object}
558
625
@@ -565,6 +632,9 @@ The `settings` object is the `cluster.settings` object at the time
565
632
If accuracy is important, use ` cluster.settings ` .
566
633
567
634
## cluster.disconnect([ callback] )
635
+ <!-- YAML
636
+ added: v0.7.7
637
+ -->
568
638
569
639
* ` callback ` {Function} called when all workers are disconnected and handles are
570
640
closed
@@ -579,6 +649,9 @@ The method takes an optional callback argument which will be called when finishe
579
649
This can only be called from the master process.
580
650
581
651
## cluster.fork([ env] )
652
+ <!-- YAML
653
+ added: v0.6.0
654
+ -->
582
655
583
656
* ` env ` {Object} Key/value pairs to add to worker process environment.
584
657
* return {cluster.Worker}
@@ -588,6 +661,9 @@ Spawn a new worker process.
588
661
This can only be called from the master process.
589
662
590
663
## cluster.isMaster
664
+ <!-- YAML
665
+ added: v0.8.1
666
+ -->
591
667
592
668
* {Boolean}
593
669
@@ -596,12 +672,18 @@ by the `process.env.NODE_UNIQUE_ID`. If `process.env.NODE_UNIQUE_ID` is
596
672
undefined, then ` isMaster ` is ` true ` .
597
673
598
674
## cluster.isWorker
675
+ <!-- YAML
676
+ added: v0.6.0
677
+ -->
599
678
600
679
* {Boolean}
601
680
602
681
True if the process is not a master (it is the negation of ` cluster.isMaster ` ).
603
682
604
683
## cluster.schedulingPolicy
684
+ <!-- YAML
685
+ added: v0.11.2
686
+ -->
605
687
606
688
The scheduling policy, either ` cluster.SCHED_RR ` for round-robin or
607
689
` cluster.SCHED_NONE ` to leave it to the operating system. This is a
@@ -617,6 +699,9 @@ distribute IOCP handles without incurring a large performance hit.
617
699
values are ` "rr" ` and ` "none" ` .
618
700
619
701
## cluster.settings
702
+ <!-- YAML
703
+ added: v0.7.1
704
+ -->
620
705
621
706
* {Object}
622
707
* ` execArgv ` {Array} list of string arguments passed to the Node.js
@@ -638,6 +723,9 @@ the settings, including the default values.
638
723
This object is not supposed to be changed or set manually, by you.
639
724
640
725
## cluster.setupMaster([ settings] )
726
+ <!-- YAML
727
+ added: v0.7.1
728
+ -->
641
729
642
730
* ` settings ` {Object}
643
731
* ` exec ` {String} file path to worker file. (Default=` process.argv[1] ` )
@@ -680,6 +768,9 @@ cluster.fork(); // http worker
680
768
This can only be called from the master process.
681
769
682
770
## cluster.worker
771
+ <!-- YAML
772
+ added: v0.7.0
773
+ -->
683
774
684
775
* {Object}
685
776
@@ -698,6 +789,9 @@ if (cluster.isMaster) {
698
789
```
699
790
700
791
## cluster.workers
792
+ <!-- YAML
793
+ added: v0.7.0
794
+ -->
701
795
702
796
* {Object}
703
797
0 commit comments