thoughtbot / Swish

Nothing but Net(working)
MIT License
363 stars 39 forks source link

Perform two requests concurrently and combine their results #98

Open sharplet opened 7 years ago

sharplet commented 7 years ago

Adds a new extension to the Client protocol that allows two requests to be performed concurrently, with their results combined into a tuple:

perform(_: RequestA, _: RequestB, completionHandler: (Result<(ResponseA, ResponseB), SwishError>) -> Void)

If either fails, the other request is cancelled and the failure result is passed to the completion handler. A new Cancelable protocol allows cancelable things to be composed together (e.g., dispatch blocks and URL session tasks).

I plan to add some tests for the basic behaviours, especially around how cancellation is handled. I honestly am not sure how to write a test for the thread-safety aspects of this code, but I'm pretty sure all reads and writes to the combined state are appropriately synchronised. I'll do another review to make sure there's no race between updating the combined state and waiting on the request group to complete.

sharplet commented 7 years ago

I also had to update the macOS deployment target to 10.10 to make use of DispatchWorkItem.