UNPKG

@react-gnome/core

Version:

## Getting Started

46 lines (45 loc) 1.4 kB
// src/runtime/timers.ts import { registerGlobal } from "./helpers/register-global.mjs"; (() => { const 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); } } registerGlobal("__setInterval_proxy", () => { const impl = globalThis["setInterval"]; function setIntervalProxy(cb, time) { const stack = new Error().stack?.split(EOL).slice(1).join(EOL); impl(() => { runWithErrorHandler(cb, "setInterval", stack); }, time); } return setIntervalProxy; }); registerGlobal("__setTimeout_proxy", () => { const impl = globalThis["setTimeout"]; function setTimeoutProxy(cb, time) { const stack = new Error().stack?.split(EOL).slice(1).join(EOL); impl(() => { runWithErrorHandler(cb, "setTimeout", stack); }, time); } return setTimeoutProxy; }); })();