Skip to content

Instantly share code, notes, and snippets.

@standinga
Last active August 17, 2019 14:17
Show Gist options
  • Save standinga/9785bed4f53a7a8486a098a727e1e190 to your computer and use it in GitHub Desktop.
Save standinga/9785bed4f53a7a8486a098a727e1e190 to your computer and use it in GitHub Desktop.
fetchData function for medium blog post about DispatchGroup and DispatchSemaphore, https://link.medium.com/zJMQPUHaeZ
func combineAsyncCalls(completionHandler: @escaping (String)->()) {
var text = ""
fetchData(0, delay: 0.4) { text += $0 }
fetchData(1, delay: 0.2) { text += $0 }
completionHandler(text)
}
combineAsyncCalls() {
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