Last active
August 17, 2019 14:16
-
-
Save standinga/2f78212a32f1a9cc0f99724b0ac87ae3 to your computer and use it in GitHub Desktop.
fetchData function for medium blog post about DispatchGroup and DispatchSemaphore, https://link.medium.com/zJMQPUHaeZ
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 combineAsyncCallsWithDispatchGroup(completionHandler: @escaping (String)->()) { | |
let group = DispatchGroup() | |
var text = "" | |
group.enter() | |
fetchData(0, delay: 0.4) { | |
text += $0 | |
group.leave() | |
} | |
group.enter() | |
fetchData(1, delay: 0.2) { | |
text += $0 | |
group.leave() | |
} | |
group.notify(queue: .main) { | |
completionHandler(text) | |
} | |
} | |
combineAsyncCallsWithDispatchGroup() { | |
print($0) | |
exit(0) | |
} | |
RunLoop.current.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment