Sniberb
Sniberb3y ago

⛄ Snowberb ⛄ – 08-58 May 19

How can I wait for multiple async functions to complete simultaneously? Promise.all but using async await
11 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Sniberb
Sniberb3y ago
But I dont want to use Promise.all I know this can be done without using Promises My example is:
const getBettingBonuses = async () => {
return await fetch('http://localhost:3001/bonuses')
}

const getCasinoBonuses = async () => {
return await fetch('http://localhost:3002/bonuses')
}
const getBettingBonuses = async () => {
return await fetch('http://localhost:3001/bonuses')
}

const getCasinoBonuses = async () => {
return await fetch('http://localhost:3002/bonuses')
}
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Sniberb
Sniberb3y ago
But I want them to start fetching at the same time Sorry for not specifying I want to call them both at the same time, and wait until both of them finish
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Sniberb
Sniberb3y ago
Yes but then async await came into play, and instead of using Promise.all().then you could do this in a cleaner way with try catch
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Sniberb
Sniberb3y ago
Sorry for wasting your time gristoi, you helped me remember what I needed from what you said
async function inParallel() {
const promise1 = printNumber1();
const promise2 = printNumber2();
const number1 = await promise1;
const number2 = await promise2;
}
async function inParallel() {
const promise1 = printNumber1();
const promise2 = printNumber2();
const number1 = await promise1;
const number2 = await promise2;
}
This is what I meant thank you!
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Sniberb
Sniberb3y ago
you're right im tripping
reactibot
reactibot3y ago
This thread hasn’t had any activity in 12 hours, so it’s now locked. Threads are closed automatically after 12 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/976770864458653696