MCPcopy Create free account
hub / github.com/getsentry/sentry-javascript / withTimeout

Function withTimeout

packages/deno/test/deno-http.test.ts:58–67  ·  view source on GitHub ↗
(p: Promise<T>, ms: number, what: string)

Source from the content-addressed store, hash-verified

56
57// Bind a promise so a real "never arrives" bug fails the test.
58function withTimeout<T>(p: Promise<T>, ms: number, what: string): Promise<T> {
59 let timer: ReturnType<typeof setTimeout> | undefined;
60 const timeout = new Promise<T>((_, reject) => {
61 timer = setTimeout(() => reject(new Error(`Timed out waiting for ${what} after ${ms}ms`)), ms);
62 });
63 // Clear the timer on either resolution so Deno's leak detector is happy.
64 return Promise.race([p, timeout]).finally(() => {
65 if (timer !== undefined) clearTimeout(timer);
66 });
67}
68
69// Activation gate — split into two skip-mirrored tests so each run exercises
70// exactly one assertion. CI on a supported Deno verifies inclusion; CI on an

Callers 1

fnFunction · 0.70

Calls 2

setTimeoutFunction · 0.85
finallyMethod · 0.65

Tested by

no test coverage detected