/** * Run tasks sequentially, resolving the resulting promises and accumulating the result in an array * @param tasks Tasks to be executed * @returns array of resolved values */ const promiseChain = (tasks: Array<() => Promise>) => tasks.reduce( (promise: Promise, task: () => Promise) => promise.then(results => task().then(result => results.concat(result))), Promise.resolve([] as T[]) ); export default promiseChain;