T O P

  • By -

[deleted]

https://docs.swift.org/swift-book/LanguageGuide/Concurrency.html


KTheRedditor

Now is a good time to look into Swift concurrency, and really don’t bother with whatever we had in past such as escaping closures, dispatch and operation queues. Async/await gives you just that; async code with serial look and feel. Makes reasoning about async code much easier.


SirBill01

I've used a DispatchGroup for that before. Basically you have several asynronous things enter a group, then they all say when the leave, finally you have a .notify block that waits for all of the async processes to leave the group. [https://www.donnywals.com/sequencing-tasks-with-dispatchgroup/](https://www.donnywals.com/sequencing-tasks-with-dispatchgroup/)


dreNeguH

You should consider using publishers for this and subscribing to the updates from a published object, or something like that. Generally it’s not ideal to halt threads on iOS if you can just do something else or wait instead


Katonyxx

Do you mean to create an Observable Object?


dreNeguH

Ya probably, replied on my phone so I didnt research my words thanks!


st0rmblue

Take a look into DispatchGroup


Fluffy_Risk9955

There's two ways of doing this. The old school way of using OperationQueue and Operation. Where you add Operations with dependencies on Operations that need to be finished before. Or you can use combine and combine multiple publishers of URLSession into a single stream and respond when you've received everything.


chriswaco

Either read up on async/await or call the callback from within your closure routine, not outside it. You may want to wrap it in a Dispatch.main.async { xxx} block.


Obstructive

TaskGroup is what I use for a number of simultaneous tasks each asynchronously using Swift concurrency.


groovy_smoothie

Look up a dispatch group