MCPcopy Index your code
hub / github.com/anomalyco/opencode / withTimeout

Function withTimeout

packages/opencode/src/util/timeout.ts:1–13  ·  view source on GitHub ↗
(promise: Promise<T>, ms: number, label?: string)

Source from the content-addressed store, hash-verified

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

Callers 12

openSocketFunction · 0.90
expectSocketRejectedFunction · 0.90
stopFunction · 0.90
waitForMessageFunction · 0.90
timeout.test.tsFile · 0.90
createFunction · 0.90
requestDiagnosticReportFunction · 0.90
stopFunction · 0.90
index.tsFile · 0.90

Calls 1

rejectFunction · 0.50

Tested by 4

openSocketFunction · 0.72
expectSocketRejectedFunction · 0.72
stopFunction · 0.72
waitForMessageFunction · 0.72