| 4 | const { get } = Reflect |
| 5 | |
| 6 | function withSafeTimers(getTimers: typeof getSafeTimers, fn: () => void) { |
| 7 | const { setTimeout, clearTimeout } = getTimers() |
| 8 | |
| 9 | const currentSetTimeout = globalThis.setTimeout |
| 10 | const currentClearTimeout = globalThis.clearTimeout |
| 11 | |
| 12 | try { |
| 13 | globalThis.setTimeout = setTimeout |
| 14 | globalThis.clearTimeout = clearTimeout |
| 15 | |
| 16 | const result = fn() |
| 17 | return result |
| 18 | } |
| 19 | finally { |
| 20 | globalThis.setTimeout = currentSetTimeout |
| 21 | globalThis.clearTimeout = currentClearTimeout |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | const promises = new Set<Promise<unknown>>() |
| 26 | |