MCPcopy Create free account
hub / github.com/arctic-cli/interface / withTimeout

Function withTimeout

packages/arctic/src/util/timeout.ts:1–14  ·  view source on GitHub ↗
(promise: Promise<T>, ms: number)

Source from the content-addressed store, hash-verified

1export function withTimeout<T>(promise: Promise<T>, ms: number): Promise<T> {
2 let timeout: NodeJS.Timeout
3 return Promise.race([
4 promise.then((result) => {
5 clearTimeout(timeout)
6 return result
7 }),
8 new Promise<never>((_, reject) => {
9 timeout = setTimeout(() => {
10 reject(new Error(`Operation timed out after ${ms}ms`))
11 }, ms)
12 }),
13 ])
14}

Callers 4

timeout.test.tsFile · 0.90
createFunction · 0.90
waitForDiagnosticsFunction · 0.90
createFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected