MCPcopy Index your code
hub / github.com/scriptscat/scriptcat / withTimeout

Function withTimeout

src/pkg/utils/with_timeout.ts:7–15  ·  view source on GitHub ↗
(promise: Promise<T>, ms: number, onTimeoutError?: () => Error)

Source from the content-addressed store, hash-verified

5 * @param onTimeoutError 可选:自定义超时错误构造器;默认抛 Error("operation timed out")
6 */
7export function withTimeout<T>(promise: Promise<T>, ms: number, onTimeoutError?: () => Error): Promise<T> {
8 let timer: ReturnType<typeof setTimeout>;
9 const timeoutPromise = new Promise<never>((_, reject) => {
10 timer = setTimeout(() => {
11 reject(onTimeoutError ? onTimeoutError() : new Error("operation timed out"));
12 }, ms);
13 });
14 return Promise.race([promise, timeoutPromise]).finally(() => clearTimeout(timer));
15}

Callers 4

executeMethod · 0.90
createExecuteScriptToolFunction · 0.90
fetchAndExtractMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected