Skip to content

Commit 275db0c

Browse files
committed
🏎 Adds additional cancellation checks to prevent unnecessary work.
1 parent eb16f30 commit 275db0c

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

β€ŽSources/HTTPNetworking/HTTPRequest.swiftβ€Ž

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,26 @@ public class HTTPRequest<T: Decodable> {
6666
var request = self.request
6767

6868
do {
69+
70+
try Task.checkCancellation()
71+
6972
// Create the adapted request.
7073
request = try await ZipAdaptor(adaptors).adapt(request, for: dispatcher.session)
7174

75+
try Task.checkCancellation()
76+
7277
// Dispatch the request and wait for a response.
7378
let (data, response) = try await dispatcher.data(for: request)
7479

80+
try Task.checkCancellation()
81+
7582
// Validate the response.
7683
try await ZipValidator(validators)
7784
.validate(response, for: request, with: data)
7885
.get()
7986

87+
try Task.checkCancellation()
88+
8089
// Convert data to the expected type
8190
return try decoder.decode(T.self, from: data)
8291
} catch {

0 commit comments

Comments
Β (0)