Post

Replies

Boosts

Views

Activity

Reply to DispatchGroup.notify is being called before all instances have left the group
If that is the case, why should the first 5 work? The same example as earlier, no block objects associated. Theoretically it should have exited before anything executes at all. var count = 0 dispatch_group.notify(queue: .main) { print("Exited") } for i in 0...10 { dispatch_group.enter() } for i in 0...10 { if i.isMultiple(of: 2) { count += 1 print(i, "count:", count) dispatch_group.leave() } else { DispatchQueue.main.asyncAfter(deadline: .now() + 1) { count += 1 print("MainAsync ", i, "count:", count) dispatch_group.leave() } } } The output: 2 count: 2 4 count: 3 6 count: 4 8 count: 5 10 count: 6 Exited MainAsync 1 count: 7 MainAsync 3 count: 8 MainAsync 5 count: 9 MainAsync 7 count: 10 MainAsync 9 count: 11 Am I missing something?
Sep ’24