Skip to content

Instantly share code, notes, and snippets.

@novinfard
Created March 4, 2019 23:27
Show Gist options
  • Save novinfard/5519c67fe561503f2d4cf2daf095be6c to your computer and use it in GitHub Desktop.
Save novinfard/5519c67fe561503f2d4cf2daf095be6c to your computer and use it in GitHub Desktop.
[Syncing multiple async tasks in Swift - code snippets 3]
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