Skip to content

Commit 05c7d8c

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

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Sources/OllamaKit/Utils/OKHTTPClient.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ 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)
37-
3836
let delegate = StreamingDelegate(
3937
urlResponseCallback: { response in
4038
do {
@@ -61,7 +59,9 @@ internal extension OKHTTPClient {
6159
continuation.finish()
6260
}
6361
)
64-
task.delegate = delegate
62+
63+
let session = URLSession(configuration: .default, delegate: delegate, delegateQueue: .main)
64+
let task = session.dataTask(with: request)
6565

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

0 commit comments

Comments
 (0)