I have a function doEverything
that takes a completion block. It calls two other functions, doAlpha
and doBeta
which both have completion blocks. These two functions should run asynchronously. I want to call doEverything
's completion block after both of the other functions have called their completion blocks.
Currently, it looks like this:
func doEverything(completion: @escaping (success) -> ())) {
var alphaSuccess = false
var betaSuccess = false
doAlpha { success in
alphaSuccess = success
}
doBeta { success in
betaSuccess = success
}
// We need to wait here
completion(alphaSuccess && betaSuccess)
}
doAlpha
and doBeta
should run at the same time and, once they've both completed, the completion block should be called with the result of alpha and beta.
I've read into dispatch groups and barriers but I'm not sure which is the most appropriate, how they both introduce new scope (with regards to the two variables I'm using) and how I should implement that.
Many thanks.