So i have a main function that calls two other functions, one of witch i have to await for result, so each funtion needs to be called separatly as they are trigered in different parts of the code, but test1 funct can run in parallel and i don't need the result, but test2 needs to provide a result.
I like for both functions to run in parallel..
this is my code so far.. cant get the two request to happen in parallel.
function test1() { yourUrl = 'http://www.google.com/' var xhr = new XMLHttpRequest(); xhr.open("POST", yourUrl, true); xhr.setRequestHeader('Content-Type', 'application/json'); xhr.onload = function(e) { console.log('get pedido') } xhr.send() } async function test2() { yourUrl = 'http://www.google.com' var xhr = new XMLHttpRequest(); xhr.open("POST", yourUrl, true); xhr.setRequestHeader('Content-Type', 'application/json'); xhr.onload = function(e) { console.log('get precio') } xhr.send() return true } async function main() { test1() await test2() } main()
test2doesn't wait for the AJAX request to complete before it returns. So there's no point in usingasync/await. You need an explicitPromisethat gets resolved in theonloadfunction.