Basic JS Async Cookbook

// aXMLHttpRequest: an asynchronous XHR function function aXMLHttpRequest(method, location, responseType="", body=undefined) { // somewhat basic; improvements welcome return new Promise( (resolve, reject) => { const xhr = new XMLHttpRequest(); xhr.open(method, location); xhr.responseType = responseType; xhr.onload = resolve; xhr.onerror = reject; xhr.send(body); return xhr; }); } // asleep: an asynchronous sleep function asleep = (delay =>…