Skip to content

Commit 8f09bf7

Browse files
author
Eric Oliver
committed
small tweak in execute parallel
1 parent 693dbb9 commit 8f09bf7

File tree

2 files changed

+31
-46
lines changed

2 files changed

+31
-46
lines changed

docs/product-stories/cli-utility/dev-prompt.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
we are ready to work on issue #13 (docs/product-stories/cli-utility/story-13-session-persistence.md) in repo https://github.com/sakamotopaya/code-agent.
2-
follow the normal git flow. create a new local branch for the story, code the tasks and unit tests that
3-
prove the task are complete.
1+
we are ready to work on issue #14 (docs/product-stories/cli-utility/story-14-non-interactive-mode.md) in repo https://github.com/sakamotopaya/code-agent.
2+
follow the normal git flow. create a new local branch for the story.
3+
code the tasks and unit tests that prove the task are complete.
44
if you need information about prior stories, you can find them locally here docs/product-stories/cli-utility
55
we often get rejected trying to push our changes. make sure and run a build and lint prior to trying to push
66
when you are finished with the code and tests, update the issue with a new comment describing your work and then

src/cli/services/BatchProcessor.ts

Lines changed: 28 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,14 @@ export class BatchProcessor extends EventEmitter {
9595
private async executeParallel(commands: BatchCommand[], settings: BatchSettings): Promise<CommandResult[]> {
9696
const maxConcurrency = settings.maxConcurrency || 3
9797
const results: CommandResult[] = []
98-
const executing: Promise<CommandResult>[] = []
9998
let commandIndex = 0
10099

101-
while (commandIndex < commands.length || executing.length > 0) {
102-
// Start new commands up to concurrency limit
103-
while (executing.length < maxConcurrency && commandIndex < commands.length) {
100+
// Process commands in batches
101+
while (commandIndex < commands.length) {
102+
const currentBatch: Promise<CommandResult>[] = []
103+
104+
// Start up to maxConcurrency commands
105+
while (currentBatch.length < maxConcurrency && commandIndex < commands.length) {
104106
const command = commands[commandIndex]
105107

106108
if (!this.shouldExecute(command, results)) {
@@ -124,53 +126,36 @@ export class BatchProcessor extends EventEmitter {
124126
return errorResult
125127
})
126128

127-
executing.push(promise)
129+
currentBatch.push(promise)
128130
commandIndex++
129131
}
130132

131-
// Wait for at least one command to complete
132-
if (executing.length > 0) {
133-
const result = await Promise.race(executing)
134-
results.push(result)
135-
136-
// Remove completed promise from executing array
137-
const completedIndex = executing.findIndex(async (p) => {
138-
try {
139-
const resolved = await Promise.race([p, Promise.resolve(result)])
140-
return resolved === result
141-
} catch {
142-
return false
133+
// Wait for all commands in this batch to complete
134+
if (currentBatch.length > 0) {
135+
const batchResults = await Promise.allSettled(currentBatch)
136+
137+
for (const settledResult of batchResults) {
138+
if (settledResult.status === "fulfilled") {
139+
const result = settledResult.value
140+
results.push(result)
141+
142+
// Update progress
143+
const progress = (results.length / commands.length) * 100
144+
this.emit("batchProgress", {
145+
completed: results.length,
146+
total: commands.length,
147+
progress: progress,
148+
})
149+
150+
// Check if we should stop on error
151+
if (!result.success && !settings.continueOnError) {
152+
return results
153+
}
143154
}
144-
})
145-
146-
if (completedIndex !== -1) {
147-
executing.splice(completedIndex, 1)
148-
}
149-
150-
// Update progress
151-
const progress = (results.length / commands.length) * 100
152-
this.emit("batchProgress", {
153-
completed: results.length,
154-
total: commands.length,
155-
progress: progress,
156-
})
157-
158-
// Check if we should stop on error
159-
if (!result.success && !settings.continueOnError) {
160-
// Cancel remaining commands
161-
break
162155
}
163156
}
164157
}
165158

166-
// Wait for any remaining executing commands
167-
const remainingResults = await Promise.allSettled(executing)
168-
for (const settledResult of remainingResults) {
169-
if (settledResult.status === "fulfilled") {
170-
results.push(settledResult.value)
171-
}
172-
}
173-
174159
return results
175160
}
176161

0 commit comments

Comments
 (0)