MCPcopy Create free account
hub / github.com/OpenPipe/OpenPipe / withTimeout

Function withTimeout

client-libs/typescript/src/shared.ts:36–58  ·  view source on GitHub ↗
(
  promise: Promise<T>,
  timeout: number,
  onTimedOut?: () => void,
)

Source from the content-addressed store, hash-verified

34});
35
36export const withTimeout = <T>(
37 promise: Promise<T>,
38 timeout: number,
39 onTimedOut?: () => void,
40): Promise<T> => {
41 return new Promise((resolve, reject) => {
42 // Set up the timeout
43 const timeoutId = setTimeout(() => {
44 onTimedOut?.();
45 reject(new APIConnectionTimeoutError({ message: "Request timed out" }));
46 }, timeout);
47
48 promise
49 .then((result) => {
50 clearTimeout(timeoutId);
51 resolve(result);
52 })
53 .catch((error) => {
54 clearTimeout(timeoutId);
55 reject(error);
56 });
57 });
58};

Callers

nothing calls this directly

Calls 3

resolveFunction · 0.50
catchMethod · 0.45
thenMethod · 0.45

Tested by

no test coverage detected