MCPcopy Index your code
hub / github.com/simstudioai/sim / processWithConcurrency

Function processWithConcurrency

apps/sim/lib/knowledge/embeddings.ts:322–339  ·  view source on GitHub ↗
(
  items: T[],
  concurrency: number,
  processor: (item: T, index: number) => Promise<R>
)

Source from the content-addressed store, hash-verified

320}
321
322async function processWithConcurrency<T, R>(
323 items: T[],
324 concurrency: number,
325 processor: (item: T, index: number) => Promise<R>
326): Promise<R[]> {
327 const results: R[] = new Array(items.length)
328 let currentIndex = 0
329
330 const workers = Array.from({ length: Math.min(concurrency, items.length) }, async () => {
331 while (currentIndex < items.length) {
332 const index = currentIndex++
333 results[index] = await processor(items[index], index)
334 }
335 })
336
337 await Promise.all(workers)
338 return results
339}
340
341export interface GenerateEmbeddingsResult {
342 embeddings: number[][]

Callers 1

generateEmbeddingsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected