Skip to content

Commit 4a37088

Browse files
committed
Use custom URLSession for streaming otherwise delegate is never called
1 parent c97a887 commit 4a37088

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Sources/OllamaKit/Utils/OKHTTPClient.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ internal extension OKHTTPClient {
3333
func stream<T: Decodable>(request: URLRequest, with responseType: T.Type) -> AsyncThrowingStream<T, Error> {
3434
return AsyncThrowingStream { continuation in
3535
Task {
36-
let task = URLSession.shared.dataTask(with: request)
36+
let session = URLSession(configuration: .default, delegate: delegate, delegateQueue: .main)
37+
let task = session.dataTask(with: request)
3738

3839
let delegate = StreamingDelegate(
3940
urlResponseCallback: { response in
@@ -61,7 +62,6 @@ internal extension OKHTTPClient {
6162
continuation.finish()
6263
}
6364
)
64-
task.delegate = delegate
6565

6666
continuation.onTermination = { terminationState in
6767
// Cancellation of our task should cancel the URLSessionDataTask

0 commit comments

Comments
 (0)