Skip to content

Instantly share code, notes, and snippets.

@ahikmatf
Created October 13, 2016 10:09
Show Gist options
  • Save ahikmatf/2542f720feb854417d5e4d600137afc6 to your computer and use it in GitHub Desktop.
Save ahikmatf/2542f720feb854417d5e4d600137afc6 to your computer and use it in GitHub Desktop.
// http://stackoverflow.com/a/28800828/5552518
import Foundation
import Alamofire
class ParallelServiceCaller {
var firstServiceCallComplete = false
var secondServiceCallComplete = false
func startServiceCalls() {
let firstRequest = Alamofire.request(.GET, "http://httpbin.org/get", parameters: ["first": "request"])
firstRequest.responseString { request, response, dataString, error in
self.firstServiceCallComplete = true
self.handleServiceCallCompletion()
}
let secondRequest = Alamofire.request(.GET, "http://httpbin.org/get", parameters: ["second": "request"])
secondRequest.responseString { request, response, dataString, error in
self.secondServiceCallComplete = true
self.handleServiceCallCompletion()
}
}
private func handleServiceCallCompletion() {
if self.firstServiceCallComplete && self.secondServiceCallComplete {
// Handle the fact that you're finished
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment