mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
worker: export workerData to ESM workers
Fixes: https://github.com/nodejs/node/issues/25765 PR-URL: https://github.com/nodejs/node/pull/25768 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
86a49ce2d8
commit
8919169bb7
@ -17,5 +17,6 @@ module.exports = {
|
||||
MessageChannel,
|
||||
threadId,
|
||||
Worker,
|
||||
parentPort: null
|
||||
parentPort: null,
|
||||
workerData: null,
|
||||
};
|
||||
|
3
test/fixtures/worker-data.mjs
vendored
Normal file
3
test/fixtures/worker-data.mjs
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import { workerData, parentPort } from 'worker_threads';
|
||||
|
||||
parentPort.postMessage(workerData);
|
16
test/parallel/test-worker-mjs-workerdata.js
Normal file
16
test/parallel/test-worker-mjs-workerdata.js
Normal file
@ -0,0 +1,16 @@
|
||||
'use strict';
|
||||
const common = require('../common');
|
||||
const fixtures = require('../common/fixtures');
|
||||
const assert = require('assert');
|
||||
const { Worker } = require('worker_threads');
|
||||
|
||||
const workerData = 'Hello from main thread';
|
||||
|
||||
const worker = new Worker(fixtures.path('worker-data.mjs'), {
|
||||
workerData,
|
||||
execArgv: ['--experimental-modules']
|
||||
});
|
||||
|
||||
worker.on('message', common.mustCall((message) => {
|
||||
assert.strictEqual(message, workerData);
|
||||
}));
|
Loading…
Reference in New Issue
Block a user