2023-03-05 00:44:41 +08:00
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
|
*/
|
|
|
|
|
|
2023-03-09 04:04:38 +08:00
|
|
|
const {MessageChannel} = require('node:worker_threads');
|
2023-03-05 00:44:41 +08:00
|
|
|
|
|
|
|
|
export default function enqueueTask(task: () => void): void {
|
2023-03-09 04:04:38 +08:00
|
|
|
const channel = new MessageChannel();
|
2023-03-10 00:20:07 +08:00
|
|
|
channel.port1.onmessage = () => {
|
|
|
|
|
channel.port1.close();
|
|
|
|
|
task();
|
|
|
|
|
};
|
2023-03-09 04:04:38 +08:00
|
|
|
channel.port2.postMessage(undefined);
|
2023-03-05 00:44:41 +08:00
|
|
|
}
|