Skip to content

Commit

Permalink
test: add a request-response test for MessageChannel
Browse files Browse the repository at this point in the history
This commit adds a request-response test for MessageChannel.

PR-URL: #21514
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
  • Loading branch information
itaysabato committed Jun 27, 2018
1 parent 8d33bbf commit 5d92b63
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test/parallel/test-message-port.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ const { MessageChannel, MessagePort } = require('worker_threads');
}));
}

{
const { port1, port2 } = new MessageChannel();

port1.onmessage = common.mustCall((message) => {
assert.strictEqual(message, 4);
port2.close(common.mustCall());
});

port1.postMessage(2);

port2.onmessage = common.mustCall((message) => {
port2.postMessage(message * 2);
});
}

{
const { port1, port2 } = new MessageChannel();

Expand Down

0 comments on commit 5d92b63

Please sign in to comment.