Skip to content

Commit

Permalink
Merge pull request #45 from outfoxx/fix/data-stream-cancel
Browse files Browse the repository at this point in the history
Cancel dataEventStream’s URLSession task when stream cancelled
  • Loading branch information
kdubb committed May 24, 2023
2 parents f2abafd + 30332ee commit 67e71a8
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Sources/Sunday/NetworkSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,13 @@ public class NetworkSession {
}

return AsyncThrowingStream(DataEvent.self) {

let task = session.dataTask(with: request)

setTaskDelegate(DataStreamDelegate(continuation: $0), for: task)

$0.onTermination = { _ in task.cancel() }

task.resume()
}

Expand Down

0 comments on commit 67e71a8

Please sign in to comment.