chunk-utils-timers.b48455ed.mjs 984 B

123456789101112131415161718192021222324252627
  1. const {
  2. setTimeout: safeSetTimeout,
  3. setInterval: safeSetInterval,
  4. clearInterval: safeClearInterval,
  5. clearTimeout: safeClearTimeout
  6. } = globalThis;
  7. function withSafeTimers(fn) {
  8. const currentSetTimeout = globalThis.setTimeout;
  9. const currentSetInterval = globalThis.setInterval;
  10. const currentClearInterval = globalThis.clearInterval;
  11. const currentClearTimeout = globalThis.clearTimeout;
  12. try {
  13. globalThis.setTimeout = safeSetTimeout;
  14. globalThis.setInterval = safeSetInterval;
  15. globalThis.clearInterval = safeClearInterval;
  16. globalThis.clearTimeout = safeClearTimeout;
  17. const result = fn();
  18. return result;
  19. } finally {
  20. globalThis.setTimeout = currentSetTimeout;
  21. globalThis.setInterval = currentSetInterval;
  22. globalThis.clearInterval = currentClearInterval;
  23. globalThis.clearTimeout = currentClearTimeout;
  24. }
  25. }
  26. export { safeClearTimeout as a, safeSetInterval as b, safeClearInterval as c, safeSetTimeout as s, withSafeTimers as w };