question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Promise.all() behaviour on tasks

See original GitHub issue

Hello, I’m having some issues getting some parallel tasks to work. The code in the Promise.all().then() is called immediately, it does not wait for the commit on the action. I thought the ‘then’ callbacks were called one after another and that ‘yield’ should wait for it. Here’s the example:

setup() {
    const store = useStore(); // https://vueuse.js.org/

    const getUserTask = useTask(function* () {
        yield store.dispatch('auth/getUser');
    }).drop();

    const getBusinessTask = useTask(function* () {
        yield store.dispatch('business/getBusiness');
    }).drop();

    Promise.all([getUserTask, getBusinessTask]).then(() => {
        console.log('all resolved');
    });
}

And one of the stores actions (the other one does the same on another endpoint) look like this (in reality, the axios call is located in another file, that’s why 2 ‘then’ callbacks):

getBusiness({commit}) {
    return axios.get('/back/api/business').then(function (response) {
        return response.data.data;
    }).then((business) => {
        commit('setBusiness', business);
    });
}

Have I misunderstood something? Thanks a lot.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
MartinMalindacommented, Dec 12, 2020

Great!

0reactions
gerardnllcommented, Dec 12, 2020

I finally got it working doing:

Promise.all([getUserTask.perform(), getDeliveriesTask.perform(), getBusinessTask.perform()]).then(() => {});

Works for me as I don’t need to track status. The same code as a parallel task wasn’t working. I didn’t try the Task group.

Thanks for your help! Awesome package.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Promise.all() - JavaScript - MDN Web Docs
The Promise.all() method is one of the promise concurrency methods. It can be useful for aggregating the results of multiple promises. It is ......
Read more >
How to Use Promise.all() - Dmitri Pavlutin
JavaScript provides a helper function Promise.all(promisesArrayOrIterable) to handle multiple promises at once, in parallel, and get the results ...
Read more >
All you need to know about Promise.all - freeCodeCamp
Promise.all is actually a promise that takes an array of promises as an input (an iterable). Then it gets resolved when all the...
Read more >
Awaiting Multiple Promises with Promise.all
This is really powerful— Promise.all allows you to run multiple async tasks independently, notifying you once all tasks have finished or if ...
Read more >
Handling errors in Promise.all - Stack Overflow
Promise.all is all or nothing. It resolves once all promises in the array resolve, or reject as soon as one of them rejects....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found