How can I update scripted dashboards with data reliant on async requests?

I have the following code for one of our async scripted dashboards:

      xmlhttp = new XMLHttpRequest();
      xmlhttp.customID = currentXmlHttpRequests.length;
      currentXmlHttpRequests.push(xmlhttp);"GET", URL, true);
      xmlhttp.onreadystatechange = myCallbackFunction();

If I set a breakpoint in myCallbackFunction() it hits, but after the other panels (which don’t rely on this async request) are already rendered onto the page. Is there a way I can prevent the sequence of events that assumes the dashboard object is complete from continuing until all of these (not many, like 4) async requests are finished (and subsequently have updated the dashboard object with the new panels)?

In JavaScript, you either have to chain together your callbacks or use a Promise library.