MCPcopy Create free account
hub / github.com/Noumena-Network/code / withTimeout

Function withTimeout

src/commands/export/export.test.tsx:9–24  ·  view source on GitHub ↗
(promise: Promise<T>, ms: number)

Source from the content-addressed store, hash-verified

7import { call } from './export.js'
8
9async function withTimeout<T>(promise: Promise<T>, ms: number): Promise<T> {
10 let timer: ReturnType<typeof setTimeout> | undefined
11 try {
12 return await Promise.race([
13 promise,
14 new Promise<never>((_, reject) => {
15 timer = setTimeout(
16 () => reject(new Error(`Timed out after ${ms}ms`)),
17 ms,
18 )
19 }),
20 ])
21 } finally {
22 if (timer) clearTimeout(timer)
23 }
24}
25
26describe('/export command', () => {
27 const tempDirs: string[] = []

Callers 1

export.test.tsxFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected