Friday, December 21, 2018

NodeJS : What is Async Waterfall?


The async library for Node and client side is a pretty nifty library which takes out some of the pain of doing things asynchronously. This example is for the server side using Node.

According to the repo, this is what the waterfall does - "Runs an array of functions in series, each passing their results to the next in the array. However, if any of the functions pass an error to the callback, the next function is not executed and the main callback is immediately called with the error."

var create = function (req, res) {
    async.waterfall([
        _function1(req),
        _function2,
        _function3
    ], function (error, success) {
        if (error) { alert('Something is wrong!'); }
        return alert('Done!');
    });
};

references:
https://coderwall.com/p/zpjrra/async-waterfall-in-nodejs

No comments:

Post a Comment