Rez Mohsnei
Rez Mohsnei

Reputation: 207

Nextjs: multiple dispatch and Promise

This is my code:

Promise.all([
        await dispatch(a()), 
        await dispatch(b()), 
        await dispatch(c()), 
        await dispatch(d())
    ]).then(console.log).catch(console.log);

And I get this log:

0: undefined
1: undefined
2: undefined
3: undefined

I want to get this data with Promise and I have to use await

Upvotes: 0

Views: 647

Answers (2)

Amit Dodake
Amit Dodake

Reputation: 20

const [a,b,c,d] = await Promise.all([
        dispatch(a()), 
        dispatch(b()), 
        dispatch(c()), 
        dispatch(d())
    ]).then().catch();

Upvotes: 0

Ahmad Alsodani
Ahmad Alsodani

Reputation: 46

the Promise.all will resolve after all async inside it are resolved so you dont need to await inside it as its an implicit await so remove the await fom inside the promis.all and check again.

Upvotes: 3

Related Questions