Skip to content

Commit

Permalink
fix: 修复超时时间的设置
Browse files Browse the repository at this point in the history
  • Loading branch information
axetroy committed Mar 12, 2024
1 parent ae35212 commit b539de4
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions runtime/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,19 +254,18 @@ export class Runtime implements IRuntime {
}

private _timeout<T>(ms: number, promise: Promise<T>) {
if (ms <= 0) return promise

return new Promise<T>((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);
});
});
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b539de4

Please sign in to comment.