Skip to content

Commit

Permalink
worker: export workerData to ESM workers
Browse files Browse the repository at this point in the history
Fixes: #25765

PR-URL: #25768
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
addaleax committed Jan 30, 2019
1 parent 86a49ce commit 8919169
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/worker_threads.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ module.exports = {
MessageChannel,
threadId,
Worker,
parentPort: null
parentPort: null,
workerData: null,
};
3 changes: 3 additions & 0 deletions test/fixtures/worker-data.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { workerData, parentPort } from 'worker_threads';

parentPort.postMessage(workerData);
16 changes: 16 additions & 0 deletions test/parallel/test-worker-mjs-workerdata.js
Original file line number Diff line number Diff line change
@@ -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);
}));

0 comments on commit 8919169

Please sign in to comment.