Promise.all() behaviour on tasks
See original GitHub issueHello, 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:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Great!
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.