We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ba3f12f commit c95ca24Copy full SHA for c95ca24
defi/src/utils/shared/withTimeout.ts
@@ -1,9 +1,13 @@
1
export const withTimeout = (millis: number, promise: any, id: string = "") => {
2
- const timeout = new Promise((resolve, reject) =>
3
- setTimeout(() => {
+ let timeoutId: NodeJS.Timeout;
+
4
+ const timeout = new Promise((_, reject) => {
5
+ timeoutId = setTimeout(() => {
6
reject(`${id} timed out after ${millis / 1000} s.`);
- resolve;
- }, millis)
7
- );
8
- return Promise.race([promise, timeout]);
9
-};
+ }, millis);
+ });
10
+ return Promise.race([promise, timeout]).finally(() => {
11
+ clearTimeout(timeoutId);
12
13
+};
0 commit comments