Created
August 30, 2020 01:42
-
-
Save standinga/5fdc2cbac3e50541da691004033232ca to your computer and use it in GitHub Desktop.
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
func combineAsyncCalls(completionHandler: @escaping (String)->()) { | |
var text = "" | |
let semaphore = DispatchSemaphore(value: 0) | |
DispatchQueue.global().async { | |
fetchData(0, delay: 0.4) { | |
text += $0 | |
semaphore.signal() | |
} | |
fetchData(1, delay: 0.2) { | |
text += $0 | |
semaphore.signal() | |
} | |
semaphore.wait() | |
semaphore.wait() | |
completionHandler(text) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment