Skip to content
Open
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
7 changes: 6 additions & 1 deletion Sources/AnyLanguageModel/LanguageModelSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public final class LanguageModelSession: @unchecked Sendable {
let session = self
let relay = AsyncThrowingStream<ResponseStream<Content>.Snapshot, any Error> { continuation in
let stream = upstream
Task {
let task = Task {
session.beginResponding()
var lastSnapshot: ResponseStream<Content>.Snapshot?
do {
Expand Down Expand Up @@ -178,6 +178,11 @@ public final class LanguageModelSession: @unchecked Sendable {
}
session.endResponding()
}
continuation.onTermination = { termination in
if case .cancelled = termination {
task.cancel()
}
}
}
return ResponseStream(stream: relay)
}
Expand Down