Minify: Use `Promise.all()` to simplify `requestURIs()`

pull/4765/head
Richard Hansen 2021-02-11 17:48:48 -05:00 committed by John McLear
parent 1ec29e0d45
commit 0c428e068e
1 changed files with 2 additions and 16 deletions

View File

@ -91,26 +91,12 @@ const requestURI = async (url, method, headers) => {
};
const requestURIs = (locations, method, headers, callback) => {
let pendingRequests = locations.length;
const responses = [];
const completed = () => {
Promise.all(locations.map((loc) => requestURI(loc, method, headers))).then((responses) => {
const statuss = responses.map((x) => x[0]);
const headerss = responses.map((x) => x[1]);
const contentss = responses.map((x) => x[2]);
callback(statuss, headerss, contentss);
};
const respondFor = (i) => (response) => {
responses[i] = response;
if (--pendingRequests === 0) {
completed();
}
};
for (let i = 0, ii = locations.length; i < ii; i++) {
requestURI(locations[i], method, headers).then(respondFor(i));
}
});
};
/**