MCPcopy Create free account
hub / github.com/codeaashu/claude-code / withTimeout

Function withTimeout

src/utils/sleep.ts:70–84  ·  view source on GitHub ↗
(
  promise: Promise<T>,
  ms: number,
  message: string,
)

Source from the content-addressed store, hash-verified

68 * returns control to the caller.
69 */
70export function withTimeout<T>(
71 promise: Promise<T>,
72 ms: number,
73 message: string,
74): Promise<T> {
75 let timer: ReturnType<typeof setTimeout> | undefined
76 const timeoutPromise = new Promise<never>((_, reject) => {
77 // eslint-disable-next-line no-restricted-syntax -- not a sleep: REJECTS after ms (timeout guard)
78 timer = setTimeout(rejectWithTimeout, ms, reject, message)
79 if (typeof timer === 'object') timer.unref?.()
80 })
81 return Promise.race([promise, timeoutPromise]).finally(() => {
82 if (timer !== undefined) clearTimeout(timer)
83 })
84}
85

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected