| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -47,8 +47,8 @@ export default function parseJSAsync(script) { | |||
| 47 | 47 | workerData: script, | |
| 48 | 48 | }); | |
| 49 | 49 | worker.on('message', resolve); | |
| 50 | - worker.on('error', reject); | ||
| 51 | - worker.on('exit', (code) => { | ||
| 50 | + worker.once('error', reject); | ||
| 51 | + worker.once('exit', (code) => { | ||
| 52 | 52 | if (code !== 0) | |
| 53 | 53 | reject(new Error(`Worker stopped with exit code ${code}`)); | |
| 54 | 54 | }); | |
@@ -73,8 +73,8 @@ if (isMainThread) { | |||
| 73 | 73 | workerData: script, | |
| 74 | 74 | }); | |
| 75 | 75 | worker.on('message', resolve); | |
| 76 | - worker.on('error', reject); | ||
| 77 | - worker.on('exit', (code) => { | ||
| 76 | + worker.once('error', reject); | ||
| 77 | + worker.once('exit', (code) => { | ||
| 78 | 78 | if (code !== 0) | |
| 79 | 79 | reject(new Error(`Worker stopped with exit code ${code}`)); | |
| 80 | 80 | }); | |
@@ -670,7 +670,7 @@ share read and write access to the same set of environment variables. | |||
| 670 | 670 | import process from 'node:process'; | |
| 671 | 671 | import { Worker, SHARE_ENV } from 'node:worker_threads'; | |
| 672 | 672 | new Worker('process.env.SET_IN_WORKER = "foo"', { eval: true, env: SHARE_ENV }) | |
| 673 | - .on('exit', () => { | ||
| 673 | + .once('exit', () => { | ||
| 674 | 674 | console.log(process.env.SET_IN_WORKER); // Prints 'foo'. | |
| 675 | 675 | }); | |
| 676 | 676 | ``` | |
@@ -680,7 +680,7 @@ new Worker('process.env.SET_IN_WORKER = "foo"', { eval: true, env: SHARE_ENV }) | |||
| 680 | 680 | ||
| 681 | 681 | const { Worker, SHARE_ENV } = require('node:worker_threads'); | |
| 682 | 682 | new Worker('process.env.SET_IN_WORKER = "foo"', { eval: true, env: SHARE_ENV }) | |
| 683 | - .on('exit', () => { | ||
| 683 | + .once('exit', () => { | ||
| 684 | 684 | console.log(process.env.SET_IN_WORKER); // Prints 'foo'. | |
| 685 | 685 | }); | |
| 686 | 686 | ``` | |
@@ -1110,7 +1110,7 @@ const { port1, port2 } = new MessageChannel(); | |||
| 1110 | 1110 | // foobar | |
| 1111 | 1111 | // closed! | |
| 1112 | 1112 | port2.on('message', (message) => console.log(message)); | |
| 1113 | - port2.on('close', () => console.log('closed!')); | ||
| 1113 | + port2.once('close', () => console.log('closed!')); | ||
| 1114 | 1114 | ||
| 1115 | 1115 | port1.postMessage('foobar'); | |
| 1116 | 1116 | port1.close(); | |
@@ -1126,7 +1126,7 @@ const { port1, port2 } = new MessageChannel(); | |||
| 1126 | 1126 | // foobar | |
| 1127 | 1127 | // closed! | |
| 1128 | 1128 | port2.on('message', (message) => console.log(message)); | |
| 1129 | - port2.on('close', () => console.log('closed!')); | ||
| 1129 | + port2.once('close', () => console.log('closed!')); | ||
| 1130 | 1130 | ||
| 1131 | 1131 | port1.postMessage('foobar'); | |
| 1132 | 1132 | port1.close(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments