Skip to content

Conversation

marcelvoss
Copy link

@marcelvoss marcelvoss commented Apr 17, 2020

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.

@marcelvoss marcelvoss force-pushed the cancellable-requests branch from b18dd6a to 71cab67 Compare April 17, 2020 07:37
@marcelvoss marcelvoss force-pushed the cancellable-requests branch from 71cab67 to d72284b Compare April 17, 2020 08:37

class CancellableRequestTests: XCTestCase {

func testCancellableRequest() {

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()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let cancellableTask = CancellableDataTask(request: task)

cancellationExpectation.fulfill()
}

task.cancel()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
task.cancel()
cancellableTask.cancel()

@OurBigAdventure
Copy link

is there an 18 month waiting period for approved changes? 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants