duemunk / Async

Syntactic sugar in Swift for asynchronous dispatches in Grand Central Dispatch
MIT License
4.59k stars 316 forks source link

Add support for DispatchGroup().notify #103

Closed JoshHrach closed 5 years ago

JoshHrach commented 8 years ago

While AsyncGroup currently supports calling wait(), that doesn't always work when dealing with a group. An example is trying to call a series of nested functions that eventually perform an asynchronous network call. The group seems to finish, but it appears to complete immediately, leading to no action within the async method and no actual 'waiting'. Thus, if you were performing a segue after waiting and were setting up data for the segue in the group, the segue would complete without any of the data actually being passed along.

Creating a DispatchGroup().notify call lets you wait until something is done and calling the action that needs to be done after the group is complete. For instance, you can create a group that calls various async methods within the group and trigger a segue after the group has completed its tasks.

I created this in the AsyncGroup struct. User can either call .notify(queue:) and specify the main queue, or .notify(qos:) and specify the Quality of Service, such as Utility, Background, User Initiated, etc.

This is a lot cleaner in Swift 3 than my previous (and now closed) pull request.

ppamorim commented 7 years ago

Please merge this!

ppamorim commented 7 years ago

@JoshHrach I tried to use your branch with Alamofire but my request get stuck, do you know why?

ppamorim commented 7 years ago

It returns NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9806)

ppamorim commented 7 years ago

Related? https://github.com/Alamofire/Alamofire/issues/1122

JoshHrach commented 7 years ago

@ppamorim It hangs while using a DispatchGroup.notify() call? Or when doing a .wait()? Because I found notify to work more reliably than wait.

I'll look at the Alamofire issue later to see if it's related.

duemunk commented 5 years ago

This project has been growing a bit old and newer Swift API quite decent. So I don't want this wrapper to grow more than what it already covers.

Thanks!