[GH-ISSUE #60] DispatchGroup wait blocks Atlantis delegate #41

Open
opened 2026-03-03 19:11:15 +03:00 by kerem · 1 comment
Owner

Originally created by @Sherlouk on GitHub (Feb 23, 2021).
Original GitHub issue: https://github.com/ProxymanApp/atlantis/issues/60

Originally assigned to: @NghiaTranUIT on GitHub.

Hey there 👋

Weird 'bug' (is it a bug? maybe not...) that lost me a good hour this evening 😅

If you have a DispatchGroup and are using the sync group.wait() function then Atlantis's delegate call is not triggered until after the group has finished.

Simplified example, I'm assuming you've already setup Atlantis with a print("Event Received") in the delegate call

let group = DispatchGroup()

let task = URLSession.shared.dataTask(with: URL(string: url)!) { _, _, _ in
  print("Network Complete")
  group.leave()
}

group.enter()
print("Starting")
task.resume()

_ = group.wait(timeout: .now() + 60)
print("Finished")

In this example you will see "Starting" "Network Complete" "Finished" "Event Received".

If you switch from .wait() to .notify() like:

group.notify(queue: .main) {
  print("Finished")
}

Then this works and you get the expected: "Starting", "Event Received", "Network Complete", "Finished".

Essentially with wait Atlantis doesn't trigger the delegate call until the entire group is finished.

Originally created by @Sherlouk on GitHub (Feb 23, 2021). Original GitHub issue: https://github.com/ProxymanApp/atlantis/issues/60 Originally assigned to: @NghiaTranUIT on GitHub. Hey there 👋 Weird 'bug' (is it a bug? maybe not...) that lost me a good hour this evening 😅 If you have a DispatchGroup and are using the sync `group.wait()` function then Atlantis's delegate call is not triggered until after the group has finished. Simplified example, I'm assuming you've already setup Atlantis with a `print("Event Received")` in the delegate call ```swift let group = DispatchGroup() let task = URLSession.shared.dataTask(with: URL(string: url)!) { _, _, _ in print("Network Complete") group.leave() } group.enter() print("Starting") task.resume() _ = group.wait(timeout: .now() + 60) print("Finished") ``` In this example you will see "Starting" "Network Complete" "Finished" "Event Received". If you switch from `.wait()` to `.notify()` like: ```swift group.notify(queue: .main) { print("Finished") } ``` Then this works and you get the expected: "Starting", "Event Received", "Network Complete", "Finished". Essentially with `wait` Atlantis doesn't trigger the delegate call until the entire group is finished.
Author
Owner

@NghiaTranUIT commented on GitHub (Feb 23, 2021):

Hey @Sherlouk,

Since the delegate is called from the main thread, so if you're using .wait(), it will block the main thread. Therefore, Atlantis's delegate could not be trigger until the Group is finished.

Maybe I can introduce the delegate queue, that you can pass the queue you would receive the delegate. It might fix your problem 😄

<!-- gh-comment-id:784583905 --> @NghiaTranUIT commented on GitHub (Feb 23, 2021): Hey @Sherlouk, Since the delegate is called from the main thread, so if you're using `.wait()`, it will block the main thread. Therefore, Atlantis's delegate could not be trigger until the Group is finished. Maybe I can introduce the delegate queue, that you can pass the queue you would receive the delegate. It might fix your problem 😄
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/atlantis#41
No description provided.