Skip to content

Commit

Permalink
feat: clear timeout when resolving
Browse files Browse the repository at this point in the history
  • Loading branch information
AkatQuas committed May 8, 2023
1 parent d142054 commit 038eddf
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/withTimeout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ export function withTimeout(sync: MutexInterface | SemaphoreInterface, timeout:
}

return new Promise((resolve, reject) => {
sync.waitForUnlock(weight).then(resolve);

setTimeout(() => reject(timeoutError), timeout);
const handle = setTimeout(() => reject(timeoutError), timeout);
sync.waitForUnlock(weight).then(() => {
clearTimeout(handle);
resolve();
});
});
},

Expand Down

0 comments on commit 038eddf

Please sign in to comment.