Daily iOS
Concurrency

DispatchGroup fan-out

In a callback-based payments app, you have to build a payment summary after three independent APIs have all finished. Where would you put DispatchGroup's enter and leave so they pair up?

How would an interviewer hear this answer? You'll see whether they'd move on, dig in, or say no, and which sentences would trip you up. Your score doesn't change.
See the short answer

Call enter() right before calling each request function, and put defer { group.leave() } on the first line of that request's completion closure so it leaves exactly once whether it ends in success, failure, or cancellation, then build the summary in notify(queue: .main).

Share a question