1

Is there anyway we can call to previous method in async.waterfall from a below method.

async.waterfall([

        function (callback) {

        },
    function (reservationStatus, callback) {

        },

        function (reservationStatusList, frontOfficeStatusList, callback) {

            callToPreviosFunction();
        }
    ], function (err, result) {
        res.json(result);
    });

2 Answers 2

3

yes We can call the previous function in async.waterfall. Please look the below modified code.

var async = require('async');

async.waterfall([
   a,b,c
], function (err, result) {
    console.log(err);
    console.log(result);
});


function a(callback) {
        console.log("function 1");
        callback(null,"true");
    };
function b(reservationStatus, callback) {
        console.log("function 2");
        callback(null,"true","true");
    };
function c(reservationStatusList, frontOfficeStatusList, callback) {
        console.log("function 3");
        b("confirmed",function(err,result){
            if(err){
                callback(err,null);
            }else{
                callback(null,result);
            }
        }); 
    };

As you can see in the above modified code of b() is again called in c().

Output:

function 1
function 2
function 3
function 2
Sign up to request clarification or add additional context in comments.

Comments

0

Return this from the current function to the next function. It should work

1 Comment

can you explain it liitle bit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.