import type { LegendMenuController } from './contexts' /** * Run an async menu action with busy gating. Uses `isBusy()` (ref-backed) so a * second click before React re-renders cannot fire the handler twice. Keeps * the menu open while pending, then clears busy and closes when it settles. */ export async function runAsyncMenuAction( menu: LegendMenuController, action: () => void | Promise, ): Promise { if (menu.isBusy()) return menu.setBusy(true) try { await action() } finally { menu.setBusy(false) menu.close() } }