Why is dispatchGroup.notify called after only the first task has exited?
In the following code the output is as follows:
1) Did the other thing
**2) Did all the things**
3) Did one thing
4) done waiting
I would expect:
1) Did the other thing
2) Did one thing
3) done waiting
**4) Did all the things**
DispatchQueue.global().async {
let dispatchGroup = DispatchGroup()
dispatchGroup.notify(queue: DispatchQueue.main) {
print("Did all the things")
}
dispatchGroup.enter()
DispatchQueue.global().asyncAfter(deadline: .now() + 10) {
print("Did one thing")
dispatchGroup.leave()
}
dispatchGroup.enter()
DispatchQueue.global().async {
print("Did the other thing")
dispatchGroup.leave()
}
dispatchGroup.wait()
print("done waiting")
}
As a side note if I perform this on the main thread it works as expected.