Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 1 addition & 17 deletions src/core/task/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6131,23 +6131,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
// Awaiting first chunk to see if it will throw an error.
this.isWaitingForFirstChunk = true

// Race between the first chunk and the abort signal
const firstChunkPromise = iterator.next()
const abortPromise = new Promise<never>((_, reject) => {
if (abortSignal.aborted) {
reject(new Error("Request cancelled by user"))
} else {
abortSignal.addEventListener(
"abort",
() => {
reject(new Error("Request cancelled by user"))
},
{ once: true },
)
}
})

const firstChunk = await Promise.race([firstChunkPromise, abortPromise])
const firstChunk = await detachOnAbort(iterator.next(), abortSignal)
// Retries after a first-chunk failure or an empty stream keep tolerance; it ends only on a real chunk.
if (!firstChunk.done && servedRefreshGeneration === this.instructionRefreshGeneration) {
this.pendingInstructionRefresh = false
Expand Down
20 changes: 20 additions & 0 deletions src/core/task/__tests__/Task.spec.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading