mirror of
https://github.com/nodejs/node.git
synced 2025-05-04 23:42:17 +00:00

This aligns `MessagePort`s more with the web API. Refs: https://github.com/nodejs/node/issues/26463 PR-URL: https://github.com/nodejs/node/pull/26487 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
32 lines
773 B
JavaScript
32 lines
773 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const { MessageChannel } = require('worker_threads');
|
|
|
|
// Make sure that .start() and .stop() do not throw on closing/closed
|
|
// MessagePorts.
|
|
// Refs: https://github.com/nodejs/node/issues/26463
|
|
|
|
function dummy() {}
|
|
|
|
{
|
|
const { port1, port2 } = new MessageChannel();
|
|
port1.close(common.mustCall(() => {
|
|
port1.on('message', dummy);
|
|
port1.off('message', dummy);
|
|
port2.on('message', dummy);
|
|
port2.off('message', dummy);
|
|
}));
|
|
port1.on('message', dummy);
|
|
port1.off('message', dummy);
|
|
port2.on('message', dummy);
|
|
port2.off('message', dummy);
|
|
}
|
|
|
|
{
|
|
const { port1 } = new MessageChannel();
|
|
port1.on('message', dummy);
|
|
port1.close(common.mustCall(() => {
|
|
port1.off('message', dummy);
|
|
}));
|
|
}
|