Created
July 9, 2019 22:13
-
-
Save standinga/ff9c7962e7af8b9305ace5e81f2e7cff to your computer and use it in GitHub Desktop.
example for adding synchronization
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
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