Perform two requests concurrently and combine their results#98
Open
Perform two requests concurrently and combine their results#98
Conversation
Contributor
Author
|
I also had to update the macOS deployment target to 10.10 to make use of |
sharplet
commented
Dec 28, 2016
Source/Models/RequestGroup.swift
Outdated
| private var state: State | ||
| private var requests = CompositeCancelable() | ||
| private let group = DispatchGroup() | ||
| private let queue = DispatchQueue(label: "com.movetogive.MTGClient.RequestGroup<\(State.self)>") |
Contributor
Author
There was a problem hiding this comment.
Oops, accidentally let this slip in
Adds a new method to the `Swish.Client` protocol, allowing two requests to be performed concurrently and combining their results in a thread-safe manner. If either request fails with an error, the other is cancelled if it is still in flight. The requests are performed on a global concurrent queue of default priority.
Exposes `scheduler` as a public property of the `Client` protocol, to allow extensions to make use of it.
1a973b9 to
48f7a53
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a new extension to the
Clientprotocol that allows two requests to be performed concurrently, with their results combined into a tuple:If either fails, the other request is cancelled and the failure result is passed to the completion handler. A new
Cancelableprotocol 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.