Apple provides a semiphor to handle multiple API calls running async called DispatchGroup.
With this MockAPI we can simulate multiple slow network calls. We want to wait until all three are finished before taking an action (like updating the UI). You could nest them:
But then you’re only running one-at-a-time. The total time here will be 8 seconds.
With a DispatchGroup they all start at the same time, and as their completion closures fire they notify the DispatchGroup they’re finished. When all three finish the DispatchGroup runs its notify closure.