then() callback firing before promise is resolved in node.js [duplicate]

As stated in a comment, pass a function to then that, when called, will call bar with your params.

function foo() {
  return new Promise(function(resolve, reject) {
    // Do some async stuff
    console.log('foo is about to resolve');
    resolve();
  });
}
    
function bar(arg) {
  console.log(arg);
}

foo().then(function(){bar('bar has fired')});

Leave a Comment