From 3258b7ea4e97302884246bd712b43fe3491ab91b Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Wed, 18 Dec 2024 15:02:35 +0800 Subject: [PATCH] f --- src/utils.ts | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 src/utils.ts diff --git a/src/utils.ts b/src/utils.ts deleted file mode 100644 index af1dd95..0000000 --- a/src/utils.ts +++ /dev/null @@ -1,29 +0,0 @@ -export class TimeoutError extends Error { - timeout: number; - - constructor(timeout: number) { - super(`Timed out after ${timeout} ms`); - this.name = this.constructor.name; - this.timeout = timeout; - Error.captureStackTrace(this, this.constructor); - } -} - -// https://betterstack.com/community/guides/scaling-nodejs/nodejs-timeouts/ -export async function promiseWithTimeout( - promiseArg: Promise, - timeout: number, -): Promise { - let timer: NodeJS.Timeout; - const timeoutPromise = new Promise((_, reject) => { - timer = setTimeout(() => { - reject(new TimeoutError(timeout)); - }, timeout); - }); - - try { - return await Promise.race([ promiseArg, timeoutPromise ]); - } finally { - clearTimeout(timer!); - } -}