Skip to content

Commit 0c277c1

Browse files
committed
Add task limiter
1 parent 40e005e commit 0c277c1

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Core/Sources/SuggestionWidget/FeatureReducers/PromptToCodePanel.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,13 @@ public struct PromptToCodePanel {
131131
let context = await contextInputController.resolveContext()
132132
let agentFactory = context.agent ?? { SimpleModificationAgent() }
133133
_ = try await withThrowingTaskGroup(of: Void.self) { group in
134-
for snippet in snippets {
134+
for (index, snippet) in snippets.enumerated() {
135+
if index > 3 { // at most 3 at a time
136+
_ = try await group.next()
137+
}
135138
group.addTask {
139+
try await Task
140+
.sleep(nanoseconds: UInt64.random(in: 0...1_000_000_000))
136141
let agent = agentFactory()
137142
let stream = agent.send(.init(
138143
code: snippet.originalCode,
@@ -153,7 +158,7 @@ public struct PromptToCodePanel {
153158
range: snippet.attachedRange,
154159
references: context.references,
155160
topics: context.topics
156-
)).timedDebounce(for: 0.5)
161+
)).timedDebounce(for: 0.4)
157162

158163
do {
159164
for try await response in stream {

0 commit comments

Comments
 (0)