-
-
Save iamFIREcracker/2912b9b5ab583190d56ab33f1943099e to your computer and use it in GitHub Desktop.
native promise mapSeries implementation
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
function mapSeries(arr) { | |
if (!Array.isArray(arr)) throw new Error('mapSeries requires an Array'); | |
const length = arr.length; | |
const results = new Array(length); | |
arr.reduce((chain, item, i) => { | |
return chain.then(() => item).then(val => results[i] = val); | |
}, Promise.resolve()) | |
.then(() => results); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment