AsyncCompatibilityKit icon indicating copy to clipboard operation
AsyncCompatibilityKit copied to clipboard

Support immediate data task cancellation

Open pd95 opened this issue 3 years ago • 1 comments

While testing my unit tests (which were working fine on iOS 15) with the back ported version of URLSession.data(for:) from AsyncCompatibilityKit the cancelation test stopped working even though the package implements task cancellation.

So I was analyzing the issue and found, that task cancellations immediately following the task creation were not considered because the URLSessionDataTask was not yet created, therefore the dataTask was nil.

So I've implemented a shouldCancel flag which is set by the onCancel handler and considered before resuming the task.

I hope this is also useful to other library users.

pd95 avatar Apr 23 '22 17:04 pd95

Hmm, I didn't see that there was already some work on cancellation handling (in #6 and #7). I've based my solution solely on the current onCancel() implementation.

Testing implementations of #6 and #7 against my test testCancellingTaskCancelsDataTaskBeforeResuming, it's visible that the immediate cancellation is not respected either.

pd95 avatar Apr 23 '22 17:04 pd95