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

Function withTimeout

src/utils/staticRender.test.tsx:6–21  ·  view source on GitHub ↗
(promise: Promise<T>, ms: number)

Source from the content-addressed store, hash-verified

4import { renderToString } from './staticRender.js'
5
6async function withTimeout<T>(promise: Promise<T>, ms: number): Promise<T> {
7 let timer: ReturnType<typeof setTimeout> | undefined
8 try {
9 return await Promise.race([
10 promise,
11 new Promise<never>((_, reject) => {
12 timer = setTimeout(
13 () => reject(new Error(`Timed out after ${ms}ms`)),
14 ms,
15 )
16 }),
17 ])
18 } finally {
19 if (timer) clearTimeout(timer)
20 }
21}
22
23describe('static renderer', () => {
24 test('resolves after the render tree exits', async () => {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected