main
js 16 lines 641 Bytes
Raw
1 // function timeout(ms: number, errorMessage: string = "Operation timed out") {
2 // let timeoutId: number;
3 // const promise = new Promise<never>((_, reject) => {
4 // timeoutId = setTimeout(() => {
5 // reject(new Error(errorMessage));
6 // }, ms);
7 // });
8 // return { promise, cancel: () => clearTimeout(timeoutId) };
9 // }
10
11 // export async function Timeout<T>(promise: Promise<T>, ms: number): Promise<T> {
12 // const { promise: timeoutPromise, cancel: cancelTimeout } = timeout(ms);
13
14 // // Race the timeout against the original promise
15 // return await Promise.race([promise, timeoutPromise]).finally(cancelTimeout);
16 // }