Skip to content

Commit a8a8f0a

Browse files
addaleaxMylesBorins
authored andcommitted
doc: add added: information for cluster
Ref: #6578 PR-URL: #7640 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 2a2971b commit a8a8f0a

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

doc/api/cluster.md

+91
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,18 @@ responsibility to manage the worker pool for your application's needs.
108108

109109

110110
## Class: Worker
111+
<!-- YAML
112+
added: v0.7.0
113+
-->
111114

112115
A Worker object contains all public information and method about a worker.
113116
In the master it can be obtained using `cluster.workers`. In a worker
114117
it can be obtained using `cluster.worker`.
115118

116119
### Event: 'disconnect'
120+
<!-- YAML
121+
added: v0.7.7
122+
-->
117123

118124
Similar to the `cluster.on('disconnect')` event, but specific to this worker.
119125

@@ -124,12 +130,18 @@ cluster.fork().on('disconnect', () => {
124130
```
125131

126132
### Event: 'error'
133+
<!-- YAML
134+
added: v0.7.3
135+
-->
127136

128137
This event is the same as the one provided by [`child_process.fork()`][].
129138

130139
In a worker you can also use `process.on('error')`.
131140

132141
### Event: 'exit'
142+
<!-- YAML
143+
added: v0.11.2
144+
-->
133145

134146
* `code` {Number} the exit code, if it exited normally.
135147
* `signal` {String} the name of the signal (eg. `'SIGHUP'`) that caused
@@ -151,6 +163,9 @@ worker.on('exit', (code, signal) => {
151163
```
152164

153165
### Event: 'listening'
166+
<!-- YAML
167+
added: v0.7.0
168+
-->
154169

155170
* `address` {Object}
156171

@@ -165,6 +180,9 @@ cluster.fork().on('listening', (address) => {
165180
It is not emitted in the worker.
166181

167182
### Event: 'message'
183+
<!-- YAML
184+
added: v0.7.0
185+
-->
168186

169187
* `message` {Object}
170188
* `handle` {undefined|Object}
@@ -220,6 +238,9 @@ if (cluster.isMaster) {
220238
```
221239

222240
### Event: 'online'
241+
<!-- YAML
242+
added: v0.7.0
243+
-->
223244

224245
Similar to the `cluster.on('online')` event, but specific to this worker.
225246

@@ -232,6 +253,9 @@ cluster.fork().on('online', () => {
232253
It is not emitted in the worker.
233254

234255
### worker.disconnect()
256+
<!-- YAML
257+
added: v0.7.7
258+
-->
235259

236260
In a worker, this function will close all servers, wait for the `'close'` event on
237261
those servers, and then disconnect the IPC channel.
@@ -293,6 +317,9 @@ if (cluster.isMaster) {
293317
```
294318

295319
### worker.id
320+
<!-- YAML
321+
added: v0.8.0
322+
-->
296323

297324
* {Number}
298325

@@ -303,17 +330,26 @@ While a worker is alive, this is the key that indexes it in
303330
cluster.workers
304331

305332
### worker.isConnected()
333+
<!-- YAML
334+
added: v0.11.14
335+
-->
306336

307337
This function returns `true` if the worker is connected to its master via its IPC
308338
channel, `false` otherwise. A worker is connected to its master after it's been
309339
created. It is disconnected after the `'disconnect'` event is emitted.
310340

311341
### worker.isDead()
342+
<!-- YAML
343+
added: v0.11.14
344+
-->
312345

313346
This function returns `true` if the worker's process has terminated (either
314347
because of exiting or being signaled). Otherwise, it returns `false`.
315348

316349
### worker.kill([signal='SIGTERM'])
350+
<!-- YAML
351+
added: v0.9.12
352+
-->
317353

318354
* `signal` {String} Name of the kill signal to send to the worker
319355
process.
@@ -330,6 +366,9 @@ Note that in a worker, `process.kill()` exists, but it is not this function,
330366
it is [`kill`][].
331367

332368
### worker.process
369+
<!-- YAML
370+
added: v0.7.0
371+
-->
333372

334373
* {ChildProcess}
335374

@@ -344,6 +383,9 @@ on `process` and `.suicide` is not `true`. This protects against accidental
344383
disconnection.
345384

346385
### worker.send(message[, sendHandle][, callback])
386+
<!-- YAML
387+
added: v0.7.0
388+
-->
347389

348390
* `message` {Object}
349391
* `sendHandle` {Handle}
@@ -373,6 +415,10 @@ if (cluster.isMaster) {
373415
```
374416

375417
### worker.suicide
418+
<!-- YAML
419+
added: v0.7.0
420+
deprecated: v6.0.0
421+
-->
376422

377423
* {Boolean}
378424

@@ -393,6 +439,9 @@ worker.kill();
393439
```
394440

395441
## Event: 'disconnect'
442+
<!-- YAML
443+
added: v0.7.9
444+
-->
396445

397446
* `worker` {cluster.Worker}
398447

@@ -411,6 +460,9 @@ cluster.on('disconnect', (worker) => {
411460
```
412461

413462
## Event: 'exit'
463+
<!-- YAML
464+
added: v0.7.9
465+
-->
414466

415467
* `worker` {cluster.Worker}
416468
* `code` {Number} the exit code, if it exited normally.
@@ -432,6 +484,9 @@ cluster.on('exit', (worker, code, signal) => {
432484
See [child_process event: 'exit'][].
433485

434486
## Event: 'fork'
487+
<!-- YAML
488+
added: v0.7.0
489+
-->
435490

436491
* `worker` {cluster.Worker}
437492

@@ -457,6 +512,9 @@ cluster.on('exit', (worker, code, signal) => {
457512
```
458513

459514
## Event: 'listening'
515+
<!-- YAML
516+
added: v0.7.0
517+
-->
460518

461519
* `worker` {cluster.Worker}
462520
* `address` {Object}
@@ -493,6 +551,9 @@ Emitted when the cluster master receives a message from any worker.
493551
See [child_process event: 'message'][].
494552

495553
## Event: 'online'
554+
<!-- YAML
555+
added: v0.7.0
556+
-->
496557

497558
* `worker` {cluster.Worker}
498559

@@ -508,6 +569,9 @@ cluster.on('online', (worker) => {
508569
```
509570

510571
## Event: 'setup'
572+
<!-- YAML
573+
added: v0.7.1
574+
-->
511575

512576
* `settings` {Object}
513577

@@ -520,6 +584,9 @@ The `settings` object is the `cluster.settings` object at the time
520584
If accuracy is important, use `cluster.settings`.
521585

522586
## cluster.disconnect([callback])
587+
<!-- YAML
588+
added: v0.7.7
589+
-->
523590

524591
* `callback` {Function} called when all workers are disconnected and handles are
525592
closed
@@ -534,6 +601,9 @@ The method takes an optional callback argument which will be called when finishe
534601
This can only be called from the master process.
535602

536603
## cluster.fork([env])
604+
<!-- YAML
605+
added: v0.6.0
606+
-->
537607

538608
* `env` {Object} Key/value pairs to add to worker process environment.
539609
* return {cluster.Worker}
@@ -543,6 +613,9 @@ Spawn a new worker process.
543613
This can only be called from the master process.
544614

545615
## cluster.isMaster
616+
<!-- YAML
617+
added: v0.8.1
618+
-->
546619

547620
* {Boolean}
548621

@@ -551,12 +624,18 @@ by the `process.env.NODE_UNIQUE_ID`. If `process.env.NODE_UNIQUE_ID` is
551624
undefined, then `isMaster` is `true`.
552625

553626
## cluster.isWorker
627+
<!-- YAML
628+
added: v0.6.0
629+
-->
554630

555631
* {Boolean}
556632

557633
True if the process is not a master (it is the negation of `cluster.isMaster`).
558634

559635
## cluster.schedulingPolicy
636+
<!-- YAML
637+
added: v0.11.2
638+
-->
560639

561640
The scheduling policy, either `cluster.SCHED_RR` for round-robin or
562641
`cluster.SCHED_NONE` to leave it to the operating system. This is a
@@ -572,6 +651,9 @@ distribute IOCP handles without incurring a large performance hit.
572651
values are `"rr"` and `"none"`.
573652

574653
## cluster.settings
654+
<!-- YAML
655+
added: v0.7.1
656+
-->
575657

576658
* {Object}
577659
* `execArgv` {Array} list of string arguments passed to the Node.js
@@ -590,6 +672,9 @@ the settings, including the default values.
590672
This object is not supposed to be changed or set manually, by you.
591673

592674
## cluster.setupMaster([settings])
675+
<!-- YAML
676+
added: v0.7.1
677+
-->
593678

594679
* `settings` {Object}
595680
* `exec` {String} file path to worker file. (Default=`process.argv[1]`)
@@ -630,6 +715,9 @@ cluster.fork(); // http worker
630715
This can only be called from the master process.
631716

632717
## cluster.worker
718+
<!-- YAML
719+
added: v0.7.0
720+
-->
633721

634722
* {Object}
635723

@@ -648,6 +736,9 @@ if (cluster.isMaster) {
648736
```
649737

650738
## cluster.workers
739+
<!-- YAML
740+
added: v0.7.0
741+
-->
651742

652743
* {Object}
653744

0 commit comments

Comments
 (0)