Created
January 9, 2020 17:56
-
-
Save pimterry/bfc06f43c9e658f2de23a152e333404a to your computer and use it in GitHub Desktop.
JS code (untested) to wait for the first success, or throw the last error.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const awaitFirst = (promises) => | |
new Promise((resolve, reject) => { | |
let count = promises.length; | |
promises.forEach(p => | |
p.then(resolve, (e) => { | |
count = count - 1; | |
if (count === 0) reject(e); | |
}) | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment