0

I have the following scenario:

async function asyncfunc1()
{
      var request = new XMLHttpRequest();
      request.open('GET', requestURL, false);
      request.responseType = 'json';
      request.send();
      return request.response;
}

var res_1 = asyncfunc1(); /* i dont to wait here, just let it work in the background */
res_2 = do some stuff....
res_3 = do more stuff
total_res= res_1 + res_2 + res_3; /* how to wait for res_1 here */
shd
  • 1,201
  • 4
  • 17
  • 29
  • Pass a callback into the function and put the code that waits on it there, or have it return a Promise and call `.then` on the Promise, putting the code that waits on it inside that – CertainPerformance May 24 '22 at 23:00
  • can you post code example – shd May 24 '22 at 23:03
  • [It's a bad idea](https://stackoverflow.com/questions/46889290/waiting-for-more-than-one-concurrent-await-operation) to start waiting "later". Use `Promise.all` instead. – Bergi May 25 '22 at 00:27

0 Answers0