Created
July 25, 2022 03:58
-
-
Save semlinker/dfaef5ed8c1812d637733d7a8e04c210 to your computer and use it in GitHub Desktop.
Promise.race
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
Promise.race = function (iterators) { | |
return new Promise((resolve, reject) => { | |
for (const iter of iterators) { | |
Promise.resolve(iter) | |
.then((res) => { | |
resolve(res); | |
}) | |
.catch((e) => { | |
reject(e); | |
}); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment