async.waterfall和async.series之间有什么区别

Bru*_*Dou 111 javascript asynchronous node.js node-async

nodejs async模块:https://github.com/caolan/async提供了2 种类似的方法,async.waterfallasync.series.

他们之间有什么区别?

Twi*_*sol 164

似乎async.waterfall允许每个函数将其结果传递给下一个函数,同时async.series将所有结果传递给最终回调.在更高的层次上,async.waterfall将是一个数据管道("给定2,乘以3,加2,除以17"),同时async.series用于必须按顺序执行的离散任务,但在其他方面是分开的.


Mar*_*rio 51

两个函数都将每个函数的返回值传递给下一个函数,然后当完成时将调用主回调,如果发生错误则传递其错误.

不同之处在于async.series(),一旦系列完成,将把所有结果传递给主回调.async.waterfall()将传递给主回调仅调用最后一个函数的结果.


Way*_*hiu 26

async.waterfall()正在处理一个action that relies on the previous outcome.

async.series() 正在处理想要的行动 see all the result at the end