Skip to content

Commit

Permalink
doc: fix examples in cluster.md
Browse files Browse the repository at this point in the history
PR-URL: #42889
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
  • Loading branch information
y1d7ng authored and RafaelGSS committed May 10, 2022
1 parent cacff07 commit 1fbfee2
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions doc/api/cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,31 +197,35 @@ Similar to the `cluster.on('exit')` event, but specific to this worker.
```mjs
import cluster from 'node:cluster';

const worker = cluster.fork();
worker.on('exit', (code, signal) => {
if (signal) {
console.log(`worker was killed by signal: ${signal}`);
} else if (code !== 0) {
console.log(`worker exited with error code: ${code}`);
} else {
console.log('worker success!');
}
});
if (cluster.isPrimary) {
const worker = cluster.fork();
worker.on('exit', (code, signal) => {
if (signal) {
console.log(`worker was killed by signal: ${signal}`);
} else if (code !== 0) {
console.log(`worker exited with error code: ${code}`);
} else {
console.log('worker success!');
}
});
}
```

```cjs
const cluster = require('node:cluster');

const worker = cluster.fork();
worker.on('exit', (code, signal) => {
if (signal) {
console.log(`worker was killed by signal: ${signal}`);
} else if (code !== 0) {
console.log(`worker exited with error code: ${code}`);
} else {
console.log('worker success!');
}
});
if (cluster.isPrimary) {
const worker = cluster.fork();
worker.on('exit', (code, signal) => {
if (signal) {
console.log(`worker was killed by signal: ${signal}`);
} else if (code !== 0) {
console.log(`worker exited with error code: ${code}`);
} else {
console.log('worker success!');
}
});
}
```

### Event: `'listening'`
Expand All @@ -235,16 +239,12 @@ added: v0.7.0
Similar to the `cluster.on('listening')` event, but specific to this worker.

```mjs
import cluster from 'node:cluster';

cluster.fork().on('listening', (address) => {
// Worker is listening
});
```

```cjs
const cluster = require('node:cluster');

cluster.fork().on('listening', (address) => {
// Worker is listening
});
Expand Down

0 comments on commit 1fbfee2

Please sign in to comment.