Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorOneNail <onenail@yeah.net>2022-05-03 00:24:13 +0300
committerGitHub <noreply@github.com>2022-05-03 00:24:13 +0300
commitf6f95bf61e84dae44b16c51ebb4a9c5b46194583 (patch)
tree1f9947a82122e0906dc04863528ec7577f61e2dd /doc
parentce29d2847b9996602e3b49523d2325aad206543c (diff)
doc: fix examples in cluster.md
PR-URL: https://github.com/nodejs/node/pull/42889 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Diffstat (limited to 'doc')
-rw-r--r--doc/api/cluster.md48
1 files changed, 24 insertions, 24 deletions
diff --git a/doc/api/cluster.md b/doc/api/cluster.md
index ce38048678c..1f7cfed56fc 100644
--- a/doc/api/cluster.md
+++ b/doc/api/cluster.md
@@ -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'`
@@ -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
});