Skip to content

Instantly share code, notes, and snippets.

@standinga
Created July 9, 2019 22:13
Show Gist options
  • Save standinga/ff9c7962e7af8b9305ace5e81f2e7cff to your computer and use it in GitHub Desktop.
Save standinga/ff9c7962e7af8b9305ace5e81f2e7cff to your computer and use it in GitHub Desktop.
example for adding synchronization
let group = DispatchGroup()
var text = ""
for i in 0..<20 {
group.enter()
fetchData(i, delay: Double.random(in: 0...0.2)) {
text += "\($0) - "
group.leave()
}
}
group.notify(queue: DispatchQueue.main) {
print(text)
exit(0)
}
RunLoop.current.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment