Skip to content

Instantly share code, notes, and snippets.

@TrejGun
Last active September 30, 2021 02:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TrejGun/7b381bee0d3c3c237ff60f3426bef223 to your computer and use it in GitHub Desktop.
Save TrejGun/7b381bee0d3c3c237ff60f3426bef223 to your computer and use it in GitHub Desktop.
mapSeries
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