UNPKG

@lobehub/ui

Version:

Lobe UI is an open-source UI component library for building AIGC web apps

30 lines (29 loc) 713 B
//#region src/base-ui/Toast/pendingQueue.ts const MAX_QUEUED_ACTIONS = 20; const QUEUE_TTL_MS = 5e3; let ready = false; let queue = []; const runWhenToastHostReady = (run) => { if (ready) { run(); return; } if (queue.length >= MAX_QUEUED_ACTIONS) queue.shift(); queue.push({ queuedAt: Date.now(), run }); }; const markToastHostReady = () => { ready = true; const pending = queue; queue = []; const now = Date.now(); for (const action of pending) if (now - action.queuedAt <= QUEUE_TTL_MS) action.run(); }; const markToastHostNotReady = () => { ready = false; }; //#endregion export { markToastHostNotReady, markToastHostReady, runWhenToastHostReady }; //# sourceMappingURL=pendingQueue.mjs.map