MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / mapLimit

Function mapLimit

apps/desktop/src/main/vault.ts:2457–2479  ·  view source on GitHub ↗
(
  items: T[],
  limit: number,
  worker: (item: T, index: number) => Promise<U>
)

Source from the content-addressed store, hash-verified

2455}
2456
2457async function mapLimit<T, U>(
2458 items: T[],
2459 limit: number,
2460 worker: (item: T, index: number) => Promise<U>
2461): Promise<U[]> {
2462 const results = new Array<U>(items.length)
2463 let nextIndex = 0
2464
2465 const run = async (): Promise<void> => {
2466 while (nextIndex < items.length) {
2467 const index = nextIndex
2468 nextIndex += 1
2469 results[index] = await worker(items[index], index)
2470 }
2471 }
2472
2473 const workers = Array.from(
2474 { length: Math.min(limit, items.length) },
2475 () => run()
2476 )
2477 await Promise.all(workers)
2478 return results
2479}
2480
2481/**
2482 * Walk every directory under the three top-level folders and return a

Callers 2

listNotesFunction · 0.85

Calls 1

runFunction · 0.70

Tested by

no test coverage detected