Skip to content

Commit 6c4b586

Browse files
authored
Update code comment about cancelling API calls (#823)
1 parent 161145d commit 6c4b586

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

native/swift/Sources/wordpress-api/WordPressAPI.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,13 @@ public actor WordPressAPI {
188188
return try await withTaskCancellationHandler {
189189
try await uploadTask.value
190190
} onCancel: {
191-
// Please note: for some reason calling `uploadTask.cancel()` here does not actually cancel
192-
// the HTTP request. But calling `progress.cancel()` does, even though `progress.cancel()` eventually
193-
// calls `uploadTask.cancel()`.
191+
// Please note: the async functions exported by uniffi-rs _do not_ support cancellation.
192+
// That means cancelling an API call like `Task { try await api.users.retrieveMe() }.cancel()`
193+
// does not cancel the underlying HTTP request sent by URLSession.
194+
//
195+
// The `progress.cancel()` in this particular function can cancel the HTTP request, because the
196+
// `progress` instance is the parent progress of `URLSessionTask.progress`, and cancelling a parent
197+
// progress automatically cancels their child progress, which is the `URLSessionTask` in this case.
194198
progress.cancel()
195199
}
196200
}

0 commit comments

Comments
 (0)