UNPKG

@reactgjs/react-gtk

Version:
43 lines (42 loc) 1.25 kB
// src/polyfills/queue-microtask.ts import { registerPolyfills } from "./shared/polyfill-global.mjs"; var EOL = "\n"; function handleTimerCbError(e, type, stack) { const stackFmtd = stack ? __console_proxy.formatStackTrace( __console_proxy.mapStackTrace(stack), 2 ) : "Stack trace not available"; __console_proxy.error( e, `${EOL}${EOL}The above error occured in a callback provided to ${type} in here:${EOL}${stackFmtd}` ); } function runWithErrorHandler(cb, type, stack) { try { const res = cb(); if (res instanceof Promise) { res.catch((e) => handleTimerCbError(e, type, stack)); } } catch (e) { handleTimerCbError(e, type, stack); } } registerPolyfills("queueMicrotask")(() => { let onNextMicrotask; function queueMicrotask(task) { const stack = new Error().stack?.split(EOL).slice(1).join(EOL); if (onNextMicrotask) { onNextMicrotask.push(task); } onNextMicrotask = [task]; imports.mainloop.idle_add(() => { if (!onNextMicrotask) return; const tasks = onNextMicrotask; onNextMicrotask = void 0; for (const task2 of tasks) { runWithErrorHandler(task2, "queueMicrotask", stack); } }, -2e3); } return { queueMicrotask }; });