Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
-1
rated 0 times [  0] [ 1]  / answers: 1 / hits: 20584  / 6 Years ago, wed, february 7, 2018, 12:00:00

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.


More From » node.js

 Answers
8
(async() => {
const [ profile, token ] = await Promise.all([
profileHelper.getUserData(username),
tokenHelper.getUserToken(username)
]);

return { profile, token };
})();

[#55229] Monday, February 5, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
irvingcarloe

Total Points: 677
Total Questions: 109
Total Answers: 96

Location: Svalbard and Jan Mayen
Member since Sun, Sep 25, 2022
2 Years ago
;