From 0c428e068e761ad53405a0939baaab86cc828df3 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Thu, 11 Feb 2021 17:48:48 -0500 Subject: [PATCH] Minify: Use `Promise.all()` to simplify `requestURIs()` --- src/node/utils/Minify.js | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/src/node/utils/Minify.js b/src/node/utils/Minify.js index 2bb8a8d66..0e6b4c4dc 100644 --- a/src/node/utils/Minify.js +++ b/src/node/utils/Minify.js @@ -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)); - } + }); }; /**