Return after all promises resolved

Viewed 4243

Having a code sample below, I'd like to get baz variable returned from 'main' function after all promises resolved.

exports.foo = function(bar) {

    var baz;

    // some kind of promises are here forming array of promises p
    // some of promises may change the baz variable

    Promise.all(p).then(() => {
      // returning expression for main function is here
      // return baz here // does not work
    });

    // return baz //cannot be done because it would be earlier than all the async promises are resolved
}
1 Answers
Related