I am currently waiting for all the promise to finish sequentially like this:
(async() => {
let profile = await profileHelper.getUserData(username);
let token = await tokenHelper.getUserToken(username);
console.log(profile);
console.log(token);
return {profile: profile, token: token};
})();
But this way, profile and token executes sequentially. Since both are independent of each other, I want both of them to be executed independently together. I think this can be done using Promise.all, but I am not sure of the syntax and I could not find any help as well.
So my question is how I can convert above api calls to run together and then return the final output.
You want to use Promise.all
use
Promise.all()
method:Wait until all ES6 promises complete, even rejected promises
The Promise.all method returns a single Promise that resolves when all of the promises in the argument have resolved or when the argument contains no promises.