Skip to content

Commit

Permalink
workers: add test for messagePort.onmessage
Browse files Browse the repository at this point in the history
PR-URL: #21510
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
Reviewed-By: Yuta Hiroto <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
Reviewed-By: Weijia Wang <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
targos committed Jun 29, 2018
1 parent 49706b4 commit 41c4b2c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/parallel/test-worker-onmessage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Flags: --experimental-worker
'use strict';
const common = require('../common');
const assert = require('assert');
const { Worker, isMainThread, parentPort } = require('worker_threads');

if (isMainThread) {
const w = new Worker(__filename);
w.on('message', common.mustCall((message) => {
assert.strictEqual(message, 4);
w.terminate();
}));
w.postMessage(2);
} else {
parentPort.onmessage = common.mustCall((message) => {
parentPort.postMessage(message * 2);
});
}

0 comments on commit 41c4b2c

Please sign in to comment.