From b539de4d71da6af88912d5c0134be84bd36847d3 Mon Sep 17 00:00:00 2001 From: Axetroy Date: Tue, 12 Mar 2024 17:58:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=B6=85=E6=97=B6?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E7=9A=84=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- runtime/fetch.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/runtime/fetch.ts b/runtime/fetch.ts index b830b79..4911fa4 100644 --- a/runtime/fetch.ts +++ b/runtime/fetch.ts @@ -254,19 +254,18 @@ export class Runtime implements IRuntime { } private _timeout(ms: number, promise: Promise) { + if (ms <= 0) return promise + return new Promise((resolve, reject) => { const timer = setTimeout(() => { reject(new RuntimeError(`timeout of ${ms}ms`)); }, ms); promise - .then((value) => { - clearTimeout(timer); - resolve(value); - }) - .catch((reason) => { + .then(resolve) + .catch(reject) + .finally(() => { clearTimeout(timer); - reject(reason); }); }); } @@ -339,7 +338,7 @@ export class Runtime implements IRuntime { } } - const timeout = config.timeout || defaults.timeout; + const timeout = config.timeout ?? defaults.timeout; const body = config.body === undefined