MCPcopy
hub / github.com/vitest-dev/vitest / withSafeTimers

Function withSafeTimers

packages/browser/src/client/tester/rpc.ts:6–23  ·  view source on GitHub ↗
(getTimers: typeof getSafeTimers, fn: () => void)

Source from the content-addressed store, hash-verified

4const { get } = Reflect
5
6function 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
25const promises = new Set<Promise<unknown>>()
26

Callers 1

safeSendCallFunction · 0.70

Calls 1

fnFunction · 0.50

Tested by

no test coverage detected