What is the difference between async.waterfall and async.series

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

What is the difference between them?

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.

What is the difference between async.waterfall and async.series , 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  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.

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.

async - Documentation, The async.waterfall() will pass only the result of the last function called to the main callback. But, the async.series will pass all the task's result to  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.

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

Node.js Async Module–Waterfall and Series, One critical difference between Series and Waterfall can be understood by carefully looking at “Program Start” and “Program End” status. In  However, the only difference between Waterfall and Series async utility is that the final callback in series receives an array of results of all the task whereas, in Waterfall, the result object of

I consider async.waterfall to be harmful, because it's hard to refactor once written and also error-prone since if you supply more arguments, other functions much change the signature.

I highly recommend async.autoInject as a great alternative, to async.waterfall. https://caolan.github.io/async/autoInject.js.html

If you do choose to use async.waterfall, I recommend storing everything in one object, so your functions don't have to change length/signatures, like so:

warning: this is a bad pattern

async.waterfall([
  cb => {
    cb(null, "one", "two");
  },
  (one, two, cb) => {
    cb(null, 1, 2, 3, 4);
  },
  (one,two,three,four,cb) => {
     // ...
  }
])

don't do it the above way. This is a much better pattern to use:

async.waterfall([
  cb => {
    cb(null, {one:"one", two:"two"});
  },
  (v, cb) => {
    cb(null, [1, 2, 3, 4]);
  },
  (v,cb) => {
     // ...
  }
])

that way you won't pull your hair out trying to make sure the function arguments have the right length. The first function only accepts one arg - callback. All the remaining ones should accept two arguments - a value and callback. Stick to the pattern and you will remain sane!

Asynchronous flow control using async, The method async.waterfall() is used to run Each function in the series takes the results  The async.waterfall() method allows you to pass values between the functions in a trickle-down manner. The waterfall() method is useful when you need the results of a previous function to perform an operation with the next function in the series.

What are the differences between "waterfall", and "series", methods , Also, can I have a async call inside another async call? Thanks in advance! Tags:​#asynchronous#javascript. difference between async.series and async.parallel. Ask Question Asked 6 years, 9 months ago. Active 2 years, 4 months ago. Viewed 10k times 22. 5. What is the

02 - Exploring Async.js - async.waterfall and async.series, The Async module has a method called series() that allows us to control the The difference between them is that series() waits for one function to finish var async = require(“async”); async.waterfall([ function(callback)  async.waterfall is a control flow mechanism that just guarantees that operations are executed in order and chain return values from the first function in the chain to the last function in the chain. If one of the functions passed to async.waterfall contains code that would be blocking then async.waterfall would also be blocked.

Using the Async Module, Interesting, what is the difference between async.series and async.waterfall? I see that both run in series but waterfall uses a task array whereas series uses a collection object? – Kangze Huang Apr 13 '16 at 14:03

Comments
  • Is it possible for either of these two functions to return a value? I've read that it's possible, but I can't find relevant information anywhere in the documentation.
  • @AndersonGreen: Nope. Looking at the library source, neither waterfall nor series returns a value. It's expected that whatever the result is will be used in the optional callback parameter.
  • The above answer may be correct back to 2012, but the correct one is the same as the next, which is: series() as it's named that ALL results as a series passed to the Final callback, and waterfall is the LAST result passed to the Final callback. See Mozilla Developer
  • This should be the answer ;-)
  • @Mario "Both functions pass the callback of the previous function" OR "Both functions pass the result of the previous function" ?
  • @user1451111, Result, lol... I am sure I had written that the first time though...
  • Awesomely created images. Did you create them yourself or got them somewhere else?
  • you should put the pictures in the answer, people will probably miss them o/w