| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6228433 commit 887c43f
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -408,7 +408,6 @@ function setupChild(evalScript) { | |||
| 408 | 408 | if (message.type === messageTypes.LOAD_SCRIPT) { | |
| 409 | 409 | const { filename, doEval, workerData, publicPort, hasStdin } = message; | |
| 410 | 410 | publicWorker.parentPort = publicPort; | |
| 411 | - setupPortReferencing(publicPort, publicPort, 'message'); | ||
| 412 | 411 | publicWorker.workerData = workerData; | |
| 413 | 412 | ||
| 414 | 413 | if (!hasStdin) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,25 @@ | |||
| 1 | + // Flags: --experimental-worker | ||
| 2 | + 'use strict'; | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + const common = require('../common'); | ||
| 5 | + const { isMainThread, parentPort, Worker } = require('worker_threads'); | ||
| 6 | + | ||
| 7 | + // This test makes sure that we manipulate the references of | ||
| 8 | + // `parentPort` correctly so that any worker threads will | ||
| 9 | + // automatically exit when there are no any other references. | ||
| 10 | + { | ||
| 11 | + if (isMainThread) { | ||
| 12 | + const worker = new Worker(__filename); | ||
| 13 | + | ||
| 14 | + worker.on('exit', common.mustCall((code) => { | ||
| 15 | + assert.strictEqual(code, 0); | ||
| 16 | + }), 1); | ||
| 17 | + | ||
| 18 | + worker.on('online', common.mustCall()); | ||
| 19 | + } else { | ||
| 20 | + const messageCallback = () => {}; | ||
| 21 | + parentPort.on('message', messageCallback); | ||
| 22 | + // The thread won't exit if we don't make the 'message' listener off. | ||
| 23 | + parentPort.off('message', messageCallback); | ||
| 24 | + } | ||
| 25 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments