| [ Web Proxy ] |
| Viewing: https://raw.githubusercontent.com/argszero/opencode/dev/packages/opencode/src/util/timeout.ts | [Back] [Original] |
export function withTimeout(promise: Promise, ms: number, label?: string): Promise {
let timeout: NodeJS.Timeout
return Promise.race([
promise.finally(() => {
clearTimeout(timeout)
}),
new Promise((_, reject) => {
timeout = setTimeout(() => {
reject(new Error(label ?? `Operation timed out after ${ms}ms`))
}, ms)
}),
])
}
| Web Proxy Viewer | New URL | Original Page |