⛄ Snowberb ⛄ – 08-58 May 19

How can I wait for multiple async functions to complete simultaneously? Promise.all but using async await
UU
Unknown User700d ago
S
Sniberb700d 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')
}
UU
Unknown User700d ago
S
Sniberb700d 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
UU
Unknown User700d ago
S
Sniberb700d 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
UU
Unknown User700d ago
S
Sniberb700d 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!
UU
Unknown User700d ago
S
Sniberb700d ago
you're right im tripping
UU
Unknown User700d ago