Created
March 4, 2019 23:27
-
-
Save novinfard/5519c67fe561503f2d4cf2daf095be6c to your computer and use it in GitHub Desktop.
[Syncing multiple async tasks in Swift - code snippets 3]
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() | |
endpoints.forEach { endpoint in | |
group.enter() | |
performNetworkRequest(url: baseUrl + endpoint) { data, error in | |
print("Task \(endpoint) is done") | |
group.leave() | |
} | |
} | |
// notify the main thread when all task are completed | |
group.notify(queue: .main) { | |
print("All Tasks are done") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment