I need to send 3 requests at once. I got some async function which works, but sends requests one by one. Where is the problem ?
async function fetcher(){
const cart = await send("GET", "https://www.mediaexpert.pl/cart/mini/data")
const cart_json = JSON.parse(cart)
if(cart_json.items.length === 0){
for(let item of [296752801, 299028489, 474510260]){
let json = JSON.stringify({"version": 1, "qty": 1, "gift_card_custom_price": 0, "id": item})
await send("POST", "https://www.mediaexpert.pl/cart/pre-x-add?precart=true", json)
}
return true
}
return false
}
const interval = setInterval(()=>{
fetcher().then(resp=>{
if(resp === false){clearInterval(interval)}
})
}, 500)
async functions wait for eachPromiseatawaitto be resolved. Don't use anasync functionorawait, if order does not matter.