Reputation:
for eg. I have two separate requests and both running in different threads then how do I get to know that both are done with their request and completed.
Upvotes: 0
Views: 50
Reputation: 2131
See below implementation , This can help you in detail:
let queue = DispatchQueue(label: "com.learn.swift", attributes: .concurrent, target: .main)
let group = DispatchGroup()
group.enter()
queue.async (group: group) {
print("1st Thread")
group.leave()
}
group.enter()
queue.async (group: group) {
print("2nd Thread")
group.leave()
}
group.notify(queue: DispatchQueue.main) {
print("All done")
}
Output:
1st Thread
2nd Thread
All done
Upvotes: 2
Reputation: 36
You can use dispatch_group
here. Enter into group using dispatch_enter
and leave by using dispatch_leave
. Both can notify by dispatch_group_notify
Upvotes: 1