Added fetching scripts

This commit is contained in:
Sebastian Seedorf
2022-08-19 18:02:11 +02:00
parent d158153fa1
commit 8227cc631d
15 changed files with 1052 additions and 1176 deletions

View File

@@ -0,0 +1,18 @@
export const promiseAllStepN = async <T>(n: number, list: (() => Promise<T>)[]) => {
const head = list.slice(0, n)
const tail = list.slice(n)
const result: T[] = []
const execute = async (promise: () => Promise<T>, i: number, runNext: () => Promise<void>) => {
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
}