Last active
September 30, 2021 02:42
-
-
Save TrejGun/7b381bee0d3c3c237ff60f3426bef223 to your computer and use it in GitHub Desktop.
mapSeries
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
export const mapSeries = <T>(tasks: Array<() => Promise<T>>): Promise<Array<T>> => { | |
return tasks.reduce((promiseChain, currentTask) => { | |
return promiseChain.then(chainResults => currentTask().then(currentResult => [...chainResults, currentResult])); | |
}, Promise.resolve([] as Array<T>)); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment