Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save dfkaye/0381a918a0b093e2b21b042e6f77ced0 to your computer and use it in GitHub Desktop.

Select an option

Save dfkaye/0381a918a0b093e2b21b042e6f77ced0 to your computer and use it in GitHub Desktop.
fake async request response batch resolve test
// 20 August 2026
// baby fake async request response batch resolve test
function Request(value) {
return new Promise(function(r) {
var response = { text() { return value } };
setTimeout(r, 100, response);
});
}
async function Batch() {
var arr = [],
a, i;
for (i = 1; i <= 10; i++) {
a = Request(i * i);
arr.push(a);
}
return Promise.all(arr);
}
console.time("test:await");
var responses = await Batch();
console.warn(responses.map(r => r.text()));
console.timeEnd("test:await");
// Array(10) [ 1, 4, 9, 16, 25, 36, 49, 64, 81, 100 ]
// await: 103ms - timer ended
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment