doc: add `added:` information for cluster · nodejs/node@c628982

@@ -108,12 +108,18 @@ responsibility to manage the worker pool for your application's needs.

108108109109110110

## Class: Worker

111+

<!-- YAML

112+

added: v0.7.0

113+

-->

111114112115

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`.

115118116119

### Event: 'disconnect'

120+

<!-- YAML

121+

added: v0.7.7

122+

-->

117123118124

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

119125

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

124130

```

125131126132

### Event: 'error'

133+

<!-- YAML

134+

added: v0.7.3

135+

-->

127136128137

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

129138130139

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

131140132141

### Event: 'exit'

142+

<!-- YAML

143+

added: v0.11.2

144+

-->

133145134146

* `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

```

152164153165

### Event: 'listening'

166+

<!-- YAML

167+

added: v0.7.0

168+

-->

154169155170

* `address` {Object}

156171

@@ -165,6 +180,9 @@ cluster.fork().on('listening', (address) => {

165180

It is not emitted in the worker.

166181167182

### Event: 'message'

183+

<!-- YAML

184+

added: v0.7.0

185+

-->

168186169187

* `message` {Object}

170188

* `handle` {undefined|Object}

@@ -220,6 +238,9 @@ if (cluster.isMaster) {

220238

```

221239222240

### Event: 'online'

241+

<!-- YAML

242+

added: v0.7.0

243+

-->

223244224245

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.

233254234255

### worker.disconnect()

256+

<!-- YAML

257+

added: v0.7.7

258+

-->

235259236260

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

```

294318295319

### worker.exitedAfterDisconnect

320+

<!-- YAML

321+

added: v6.0.0

322+

-->

296323297324

* {Boolean}

298325

@@ -314,6 +341,9 @@ worker.kill();

314341

```

315342316343

### worker.id

344+

<!-- YAML

345+

added: v0.8.0

346+

-->

317347318348

* {Number}

319349

@@ -324,17 +354,26 @@ While a worker is alive, this is the key that indexes it in

324354

cluster.workers

325355326356

### worker.isConnected()

357+

<!-- YAML

358+

added: v0.11.14

359+

-->

327360328361

This function returns `true` if the worker is connected to its master via its IPC

329362

channel, `false` otherwise. A worker is connected to its master after it's been

330363

created. It is disconnected after the `'disconnect'` event is emitted.

331364332365

### worker.isDead()

366+

<!-- YAML

367+

added: v0.11.14

368+

-->

333369334370

This function returns `true` if the worker's process has terminated (either

335371

because of exiting or being signaled). Otherwise, it returns `false`.

336372337373

### worker.kill([signal='SIGTERM'])

374+

<!-- YAML

375+

added: v0.9.12

376+

-->

338377339378

* `signal` {String} Name of the kill signal to send to the worker

340379

process.

@@ -351,6 +390,9 @@ Note that in a worker, `process.kill()` exists, but it is not this function,

351390

it is [`kill`][].

352391353392

### worker.process

393+

<!-- YAML

394+

added: v0.7.0

395+

-->

354396355397

* {ChildProcess}

356398

@@ -365,6 +407,9 @@ on `process` and `.exitedAfterDisconnect` is not `true`. This protects against

365407

accidental disconnection.

366408367409

### worker.send(message[, sendHandle][, callback])

410+

<!-- YAML

411+

added: v0.7.0

412+

-->

368413369414

* `message` {Object}

370415

* `sendHandle` {Handle}

@@ -394,6 +439,10 @@ if (cluster.isMaster) {

394439

```

395440396441

### worker.suicide

442+

<!-- YAML

443+

added: v0.7.0

444+

deprecated: v6.0.0

445+

-->

397446398447

> Stability: 0 - Deprecated: Use [`worker.exitedAfterDisconnect`][] instead.

399448

@@ -420,6 +469,9 @@ This API only exists for backwards compatibility and will be removed in the

420469

future.

421470422471

## Event: 'disconnect'

472+

<!-- YAML

473+

added: v0.7.9

474+

-->

423475424476

* `worker` {cluster.Worker}

425477

@@ -438,6 +490,9 @@ cluster.on('disconnect', (worker) => {

438490

```

439491440492

## Event: 'exit'

493+

<!-- YAML

494+

added: v0.7.9

495+

-->

441496442497

* `worker` {cluster.Worker}

443498

* `code` {Number} the exit code, if it exited normally.

@@ -459,6 +514,9 @@ cluster.on('exit', (worker, code, signal) => {

459514

See [child_process event: 'exit'][].

460515461516

## Event: 'fork'

517+

<!-- YAML

518+

added: v0.7.0

519+

-->

462520463521

* `worker` {cluster.Worker}

464522

@@ -484,6 +542,9 @@ cluster.on('exit', (worker, code, signal) => {

484542

```

485543486544

## Event: 'listening'

545+

<!-- YAML

546+

added: v0.7.0

547+

-->

487548488549

* `worker` {cluster.Worker}

489550

* `address` {Object}

@@ -538,6 +599,9 @@ cluster.on('message', function(worker, message, handle) {

538599

```

539600540601

## Event: 'online'

602+

<!-- YAML

603+

added: v0.7.0

604+

-->

541605542606

* `worker` {cluster.Worker}

543607

@@ -553,6 +617,9 @@ cluster.on('online', (worker) => {

553617

```

554618555619

## Event: 'setup'

620+

<!-- YAML

621+

added: v0.7.1

622+

-->

556623557624

* `settings` {Object}

558625

@@ -565,6 +632,9 @@ The `settings` object is the `cluster.settings` object at the time

565632

If accuracy is important, use `cluster.settings`.

566633567634

## cluster.disconnect([callback])

635+

<!-- YAML

636+

added: v0.7.7

637+

-->

568638569639

* `callback` {Function} called when all workers are disconnected and handles are

570640

closed

@@ -579,6 +649,9 @@ The method takes an optional callback argument which will be called when finishe

579649

This can only be called from the master process.

580650581651

## cluster.fork([env])

652+

<!-- YAML

653+

added: v0.6.0

654+

-->

582655583656

* `env` {Object} Key/value pairs to add to worker process environment.

584657

* return {cluster.Worker}

@@ -588,6 +661,9 @@ Spawn a new worker process.

588661

This can only be called from the master process.

589662590663

## cluster.isMaster

664+

<!-- YAML

665+

added: v0.8.1

666+

-->

591667592668

* {Boolean}

593669

@@ -596,12 +672,18 @@ by the `process.env.NODE_UNIQUE_ID`. If `process.env.NODE_UNIQUE_ID` is

596672

undefined, then `isMaster` is `true`.

597673598674

## cluster.isWorker

675+

<!-- YAML

676+

added: v0.6.0

677+

-->

599678600679

* {Boolean}

601680602681

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

603682604683

## cluster.schedulingPolicy

684+

<!-- YAML

685+

added: v0.11.2

686+

-->

605687606688

The scheduling policy, either `cluster.SCHED_RR` for round-robin or

607689

`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.

617699

values are `"rr"` and `"none"`.

618700619701

## cluster.settings

702+

<!-- YAML

703+

added: v0.7.1

704+

-->

620705621706

* {Object}

622707

* `execArgv` {Array} list of string arguments passed to the Node.js

@@ -638,6 +723,9 @@ the settings, including the default values.

638723

This object is not supposed to be changed or set manually, by you.

639724640725

## cluster.setupMaster([settings])

726+

<!-- YAML

727+

added: v0.7.1

728+

-->

641729642730

* `settings` {Object}

643731

* `exec` {String} file path to worker file. (Default=`process.argv[1]`)

@@ -680,6 +768,9 @@ cluster.fork(); // http worker

680768

This can only be called from the master process.

681769682770

## cluster.worker

771+

<!-- YAML

772+

added: v0.7.0

773+

-->

683774684775

* {Object}

685776

@@ -698,6 +789,9 @@ if (cluster.isMaster) {

698789

```

699790700791

## cluster.workers

792+

<!-- YAML

793+

added: v0.7.0

794+

-->

701795702796

* {Object}

703797