Spaces:
Runtime error
Runtime error
Download apps/api/src/services/expense/shared/with-timeout.ts from ClaraSu/llm-router: direct link, hf CLI and curl.
- Browser
- Download file 506 Bytes
-
https://huggingface.co/spaces/ClaraSu/llm-router/resolve/main/apps/api/src/services/expense/shared/with-timeout.ts
- Command line
-
hf download hf://spaces/ClaraSu/llm-router/apps/api/src/services/expense/shared/with-timeout.ts
-
curl -L -o with-timeout.ts https://huggingface.co/spaces/ClaraSu/llm-router/resolve/main/apps/api/src/services/expense/shared/with-timeout.ts
506 Bytes
| export async function withTimeout<T>(promise: Promise<T>, ms: number, message: string): Promise<T> { | |
| // The Promise constructor runs its executor synchronously, so `handle` is | |
| // always assigned before the `finally` below ever runs. | |
| let handle: ReturnType<typeof setTimeout> | |
| const timeout = new Promise<never>((_, reject) => { | |
| handle = setTimeout(() => reject(new Error(message)), ms) | |
| }) | |
| try { | |
| return await Promise.race([promise, timeout]) | |
| } finally { | |
| clearTimeout(handle!) | |
| } | |
| } | |