summaryrefslogtreecommitdiff
path: root/test/parallel/test-worker-message-port-close-while-receiving.js
blob: d6f73caff1fb66694c1a2967b7f4da8b5ef476d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
'use strict';
const common = require('../common');

const { MessageChannel } = require('worker_threads');

// Make sure that closing a message port while receiving messages on it does
// not stop messages that are already in the queue from being emitted.

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

port1.on('message', common.mustCall(() => {
  port1.close();
}, 2));
port2.postMessage('foo');
port2.postMessage('bar');