Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCD pattern for chaining async operations while piping the results

Tags:

Coming from JavaScript world using async javascript promises, and I believe the same is done using GCD async queues in Swift.

Can you point me to an example where 2 to 3 async functions are specified in a queue, with one async operation feeding the result to the second, and second feeding the result to the third (commonly known as piping the results) and then finally a result and error handler.

All functions restrict to a single argument by design.

If any error let's say during function 2, function 3 is skipped and error is passed straight down to the error handler.

Looking for a native solution instead of any 3rd party Promise or Monad library.

Appreciate swift 3.0 code.

Edit. Also learned from the example that steps are more like a manual linear path in GCD where developer is the one feeding result to the next and checking error each time, Any Functional Programming possible using Function Compositions?

I want to avoid Pyramid of Doom and looking for a linear async programming.

like image 741
user2727195 Avatar asked Jul 06 '16 08:07

user2727195


1 Answers

I've reached out to Apple with a support request and they referred me to this WWDC15 video Advance NSOperations.

I didn't get to see how to pipe results from one sub operation to the other, now based on this video if someone can write some comprehensive example code where one routine after executing passing results to the next, I'd accept the answer.

like image 169
user2727195 Avatar answered Sep 28 '22 02:09

user2727195