R
Reactiflux

⛄ Snowberb ⛄ – 08-58 May 19

⛄ Snowberb ⛄ – 08-58 May 19

S⛄Snowberb⛄5/19/2022
How can I wait for multiple async functions to complete simultaneously? Promise.all but using async await
UUUnknown User5/19/2022
Message Not Public
Sign In & Join Server To View
S⛄Snowberb⛄5/19/2022
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')
}
UUUnknown User5/19/2022
Message Not Public
Sign In & Join Server To View
S⛄Snowberb⛄5/19/2022
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
UUUnknown User5/19/2022
2 Messages Not Public
Sign In & Join Server To View
S⛄Snowberb⛄5/19/2022
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
UUUnknown User5/19/2022
2 Messages Not Public
Sign In & Join Server To View
S⛄Snowberb⛄5/19/2022
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!
UUUnknown User5/19/2022
Message Not Public
Sign In & Join Server To View
S⛄Snowberb⛄5/19/2022
you're right im tripping
UUUnknown User5/19/2022
Message Not Public
Sign In & Join Server To View

Looking for more? Join the community!

R
Reactiflux

⛄ Snowberb ⛄ – 08-58 May 19

Join Server
Want results from more Discord servers?
Add your server