const db = {
    name: Promise.resolve('jack'),
    addr: Promise.resolve('tapuia 72'),
    fav: Promise.resolve('kaisen')
};

Promise.all([
    db.name,
    db.addr,
    db.fav
]).then(results => {
    console.log(results);
}).catch(err => {});

Here, all three of the Promises will be triggered simultaneously, and will run in parallel. Running calls in parallel is, of course, much more efficient than running them serially. Also, Promise.all guarantees that the final then receives an array of results ordered to synchronize result position with caller position.

results matching ""

    No results matching ""