mirror of
https://github.com/zebrajr/react.git
synced 2026-01-15 12:15:22 +00:00
Node's MessageChannel implementation will leak if you don't explicitly close the port. This updates the enqueueTask function we use in our internal testing helpers to close the port once it's no longer needed.
20 lines
486 B
JavaScript
20 lines
486 B
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow
|
|
*/
|
|
|
|
const {MessageChannel} = require('node:worker_threads');
|
|
|
|
export default function enqueueTask(task: () => void): void {
|
|
const channel = new MessageChannel();
|
|
channel.port1.onmessage = () => {
|
|
channel.port1.close();
|
|
task();
|
|
};
|
|
channel.port2.postMessage(undefined);
|
|
}
|