MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / all

Function all

source code/utils/generators.ts:34–74  ·  view source on GitHub ↗
(
  generators: AsyncGenerator<A, void>[],
  concurrencyCap = Infinity,
)

Source from the content-addressed store, hash-verified

32
33// Run all generators concurrently up to a concurrency cap, yielding values as they come in
34export async function* all<A>(
35 generators: AsyncGenerator<A, void>[],
36 concurrencyCap = Infinity,
37): AsyncGenerator<A, void> {
38 const next = (generator: AsyncGenerator<A, void>) => {
39 const promise: Promise<QueuedGenerator<A>> = generator
40 .next()
41 .then(({ done, value }) => ({
42 done,
43 value,
44 generator,
45 promise,
46 }))
47 return promise
48 }
49 const waiting = [...generators]
50 const promises = new Set<Promise<QueuedGenerator<A>>>()
51
52 // Start initial batch up to concurrency cap
53 while (promises.size < concurrencyCap && waiting.length > 0) {
54 const gen = waiting.shift()!
55 promises.add(next(gen))
56 }
57
58 while (promises.size > 0) {
59 const { done, value, generator, promise } = await Promise.race(promises)
60 promises.delete(promise)
61
62 if (!done) {
63 promises.add(next(generator))
64 // TODO: Clean this up
65 if (value !== undefined) {
66 yield value
67 }
68 } else if (waiting.length > 0) {
69 // Start a new generator when one finishes
70 const nextGen = waiting.shift()!
71 promises.add(next(nextGen))
72 }
73 }
74}
75
76export async function toArray<A>(
77 generator: AsyncGenerator<A, void>,

Callers 2

executeHooksFunction · 0.85
runToolsConcurrentlyFunction · 0.85

Calls 4

nextFunction · 0.85
shiftMethod · 0.80
deleteMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected