MCPcopy Create free account
hub / github.com/VirtualHotBar/NetMount / concurrentFetch

Function concurrentFetch

src/utils/request.ts:394–417  ·  view source on GitHub ↗
(
  requests: Array<() => Promise<T>>,
  concurrency: number = 5
)

Source from the content-addressed store, hash-verified

392 * @returns 所有请求结果
393 */
394export async function concurrentFetch<T>(
395 requests: Array<() => Promise<T>>,
396 concurrency: number = 5
397): Promise<T[]> {
398 const results: T[] = new Array(requests.length)
399 const executing = new Set<Promise<void>>()
400
401 for (let i = 0; i < requests.length; i++) {
402 const request = requests[i]!
403 const promise = (async () => {
404 results[i] = await request()
405 })()
406
407 executing.add(promise)
408 promise.finally(() => executing.delete(promise))
409
410 if (executing.size >= concurrency) {
411 await Promise.race(executing)
412 }
413 }
414
415 await Promise.all(executing)
416 return results
417}

Callers

nothing calls this directly

Calls 1

addMethod · 0.80

Tested by

no test coverage detected