Skip to content

Commit 887c43f

Browse files
oyydtargos
authored andcommitted
worker: remove redundant function call to setupPortReferencing
There is no need to call `setupPortReferencing` in `setupChild` as which has been called with the same arguments in the `oninit` prototype method of `MessagePort`. PR-URL: #22298 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 6228433 commit 887c43f

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/internal/worker.js

-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,6 @@ function setupChild(evalScript) {
408408
if (message.type === messageTypes.LOAD_SCRIPT) {
409409
const { filename, doEval, workerData, publicPort, hasStdin } = message;
410410
publicWorker.parentPort = publicPort;
411-
setupPortReferencing(publicPort, publicPort, 'message');
412411
publicWorker.workerData = workerData;
413412

414413
if (!hasStdin)
Original file line numberDiff line numberDiff 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+
}

0 commit comments

Comments
 (0)