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 <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>
  • Loading branch information
addaleax authored and targos committed Jan 30, 2019
1 parent d04c0bb commit e0597a7
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 e0597a7

Please sign in to comment.