Skip to content

Commit

Permalink
fix: prevent unhandled rejections in racePromisesWithCutoff (#5627)
Browse files Browse the repository at this point in the history
* Log unhandled promise rejections

* Resolve cutoffPromise and timeoutPromise instead of rejecting

* Remove unhandled promise rejections test logs

* Use sleep instead of new Promise/setTimeout
  • Loading branch information
nflaig authored Jun 12, 2023
1 parent 4ea12e3 commit 739febb
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions packages/utils/src/promise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,12 @@ export async function racePromisesWithCutoff<T>(
): Promise<(Error | T)[]> {
// start the cutoff and timeout timers
let cutoffObserved = false;
const cutoffPromise = new Promise((_resolve, reject) => setTimeout(reject, cutoffMs)).catch((e) => {
const cutoffPromise = sleep(cutoffMs).then(() => {
cutoffObserved = true;
throw e;
});
let timeoutObserved = false;
const timeoutPromise = new Promise((_resolve, reject) => setTimeout(reject, timeoutMs)).catch((e) => {
const timeoutPromise = sleep(timeoutMs).then(() => {
timeoutObserved = true;
throw e;
});
const startTime = Date.now();

Expand Down

0 comments on commit 739febb

Please sign in to comment.