0

I am using the async waterfall model to execute functions in sequence. However, within each function it does not execute statement in series. For instance below

var serviceconfig = loadCsv();
callback(null, serviceconfig);

I want the callback to only execute when the loadCsv() function returns the value but looks like it would continue the execution

apiRoutes.get('/api/:service/:subject', function(req, res) {

async.waterfall([
  function(callback){
    var serviceconfig = loadCsv();
    callback(null, serviceconfig);

  },
  function(serviceconfig, callback){
    console.log("serviceconfig final: " + serviceconfig);
    callback(null, 'd');
  },
  function(argd, callback){     

  }], function (err, result) {

  }
)


});

1 Answer 1

1

You could, if it is possible for you, send the callback to the loadCsv, and let it handle it.

var serviceconfig = loadCsv(callback);

And then in loadCsv:

function loadCsv(callback) {
    // code
    callback(null, result);
}
Sign up to request clarification or add additional context in comments.

Comments

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.