| 1 | /** |
| 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | * |
| 4 | * This source code is licensed under the MIT license found in the |
| 5 | * LICENSE file in the root directory of this source tree. |
| 6 | * |
| 7 | * @flow |
| 8 | */ |
| 9 | |
| 10 | const {MessageChannel} = require('node:worker_threads'); |
| 11 | |
| 12 | export default function enqueueTask(task: () => void): void { |
| 13 | const channel = new MessageChannel(); |
| 14 | // $FlowFixMe[prop-missing] |
| 15 | channel.port1.onmessage = () => { |
| 16 | channel.port1.close(); |
| 17 | task(); |
| 18 | }; |
| 19 | channel.port2.postMessage(undefined); |
| 20 | } |