Skip to content

Commit

Permalink
Simplify (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Aug 19, 2021
1 parent 5abdd61 commit 471c492
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
import delay from 'yoctodelay';

export default async function pMinDelay(promise, minimumDelay, {delayRejection = true} = {}) {
let promiseError;
await Promise[delayRejection ? 'allSettled' : 'all']([
promise,
delay(minimumDelay)
]);

if (delayRejection) {
// TODO: Use try/catch here.
// eslint-disable-next-line promise/prefer-await-to-then
promise = promise.catch(error => {
promiseError = error;
});
}

const [value] = await Promise.all([promise, delay(minimumDelay)]);

if (promiseError) {
throw promiseError;
}

return value;
return promise;
}

0 comments on commit 471c492

Please sign in to comment.