-
Notifications
You must be signed in to change notification settings - Fork 36
Allow cancellation for network requests #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
b18dd6a
to
71cab67
Compare
71cab67
to
d72284b
Compare
|
||
class CancellableRequestTests: XCTestCase { | ||
|
||
func testCancellableRequest() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tests the mock but is missing the test for the CancellableDataTask
struct.
|
||
func testCancellableRequest() { | ||
let task = MockURLSessionDataTask() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let cancellableTask = CancellableDataTask(request: task) |
cancellationExpectation.fulfill() | ||
} | ||
|
||
task.cancel() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
task.cancel() | |
cancellableTask.cancel() |
is there an 18 month waiting period for approved changes? 🤔 |
Hey there,
while browsing through the code base I noticed that at the moment it is impossible to cancel any network requests, although this is something that needs to happen rather often in mobile applications (reachability etc).
I thought about a way to sensibly return the requests without exposing implementation details of the networking layer to any module integrators and went with protocols (yay). This way we can don't need to expose the URLSessionDataTask objects themselves but only expose a protocol that has a single
cancel()
function. Tl;Dr: even though the networking code might change at some point, the integrator will still only receive any object conforming to the protocol. I think this is the cleanest solution for this.Most importantly: the return value is discardable (thanks to
@discardableResult
) and will not change anything for current integrators.