GeezerVison is showing github.com — worker: remove redundant function call to `setupPortReferencing` · nodejs/node@887c43f
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/internal/worker.js -1Lines changed: 0 additions & 1 deletion | 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) |
|
Collapse file
Copy file name to clipboard +25Lines changed: 25 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 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 | +} |