mirror of
https://github.com/nodejs/node.git
synced 2025-05-03 18:37:06 +00:00

Having an experimental feature behind a flag makes change if we are expecting significant breaking changes to its API. Since the Worker API has been essentially stable since its initial introduction, and no noticeable doubt about possibly not keeping the feature around has been voiced, removing the flag and thereby reducing the barrier to experimentation, and consequently receiving feedback on the implementation, seems like a good idea. PR-URL: https://github.com/nodejs/node/pull/25361 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Yuta Hiroto <hello@hiroppy.me> Reviewed-By: Shingo Inoue <leko.noor@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Masashi Hirano <shisama07@gmail.com> Reviewed-By: Weijia Wang <starkwang@126.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
'use strict';
|
|
require('../common');
|
|
|
|
// This test ensures that the messages from the internal
|
|
// message port are drained before the call to 'kDispose',
|
|
// and so all the stdio messages from the worker are processed
|
|
// in the parent and are pushed to their target streams.
|
|
|
|
const assert = require('assert');
|
|
const {
|
|
Worker,
|
|
isMainThread,
|
|
parentPort,
|
|
threadId,
|
|
} = require('worker_threads');
|
|
|
|
if (isMainThread) {
|
|
const workerIdsToOutput = new Map();
|
|
|
|
for (let i = 0; i < 2; i++) {
|
|
const worker = new Worker(__filename, { stdout: true });
|
|
const workerOutput = [];
|
|
workerIdsToOutput.set(worker.threadId, workerOutput);
|
|
worker.on('message', console.log);
|
|
worker.stdout.on('data', (chunk) => {
|
|
workerOutput.push(chunk.toString().trim());
|
|
});
|
|
}
|
|
|
|
process.on('exit', () => {
|
|
for (const [threadId, workerOutput] of workerIdsToOutput) {
|
|
assert.ok(workerOutput.includes(`1 threadId: ${threadId}`));
|
|
assert.ok(workerOutput.includes(`2 threadId: ${threadId}`));
|
|
}
|
|
});
|
|
} else {
|
|
console.log(`1 threadId: ${threadId}`);
|
|
console.log(`2 threadId: ${threadId}`);
|
|
parentPort.postMessage(Array(100).fill(1));
|
|
}
|