What is the difference between async.waterfall and

2019-01-30 04:36发布

The nodejs async module: https://github.com/caolan/async provides 2 similar methods, async.waterfall and async.series.

What is the difference between them?

3条回答
闹够了就滚
2楼-- · 2019-01-30 04:59

It appears that async.waterfall allows each function to pass its results on to the next function, while async.series passes all results to the final callback. At a higher level, async.waterfall would be for a data pipeline ("given 2, multiply it by 3, add 2, and divide by 17"), while async.series would be for discrete tasks that must be performed in order, but are otherwise separate.

查看更多
等我变得足够好
3楼-- · 2019-01-30 05:06

async.waterfall() is dealing with an action that relies on the previous outcome.

async.series() is dealing with an action that wants to see all the result at the end

查看更多
Lonely孤独者°
4楼-- · 2019-01-30 05:16

Both functions pass the return value, of every function to the next, then when done will call the main callback, passing its error, if an error happens.

The difference is that async.series(), once the series have finished, will pass all the results to the main callback. async.waterfall() will pass to the main callback only the result of the last function called.

查看更多
登录 后发表回答