对于链接异步操作,同时通过管道将结果GCD模式 [英] GCD pattern for chaining async operations while piping the results

查看:335
本文介绍了对于链接异步操作,同时通过管道将结果GCD模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用异步JavaScript的承诺从JavaScript世界的到来,我相信同样的斯威夫特使用GCD异步队列就完成了。

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

您可以点我到2〜3异步函数在一个队列指定一个例子,一个异步操作喂养结果到第二个,第二喂结果到第三(俗称管道的结果),并然后最后的结果和错误处理程序。

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.

如果任何错误让功能2时说,功能3被跳过,错误传递直线下降到错误处理程序。

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.

鸭preciate SWIFT 3.0 code。

Appreciate swift 3.0 code.

编辑。同样来自例子步骤更像是GCD,其中开发人员每次一进料结果到下一个,并检查错误手动线性路径了解到,任何功能编程可以使用的复合函数

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?

我想避免厄运的金字塔和寻找<一href=\"http://image.slidesharecdn.com/promisesqonline-130314132109-phpapp01/95/javascript-promisesq-library-11-638.jpg?cb=1363267354\"相对=nofollow>线性异步编程

推荐答案

我伸出苹果支持请求,他们叫我去这个WWDC15视频的高级NSOperations

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

我没能看到管道如何从结果一个子操作,另外,现在在此基础上的视频,如果有人能写一些COM prehensive例如code其中执行结果合格后一个例程接下来,我会接受的答案。

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.

这篇关于对于链接异步操作,同时通过管道将结果GCD模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆