export const promiseAllStepN = async (n: number, list: (() => Promise)[]) => { const head = list.slice(0, n) const tail = list.slice(n) const result: T[] = [] const execute = async (promise: () => Promise, i: number, runNext: () => Promise) => { result[i] = await promise() await runNext() } const runNext = async () => { const i = list.length - tail.length const promise = tail.shift() if (promise !== undefined) { await execute(promise, i, runNext) } } await Promise.all(head.map((promise, i) => execute(promise, i, runNext))) return result }