Sign in
Log inSign up

Will child callback wait when parent callback is called in async? If not, does it has any effect on performance?

riot cse's photo
riot cse
·Apr 19, 2016

I came across this scenario while coding recently. I have an async function like this.

exports.dummy = function (req, res, next) {
  async.waterfall([
    function (cb) {
      /.../
      cb();
    }, function (cb1) {
      if (/*something*/) {
        cb1();
      } else {
        next(); //my question is about this one
      }
    }, function (cb2) {
      /*...*/
      cb2();
    }
  ], next);
};

This was my sample scenario where I called parent callback "next" in middle of async, and got this doubt. Does async wait for its internal callback "cb1" or terminates it? If it terminates, what about performance? Anything to take care about these callbacks?