From d3fc0c1eae312a6a05464a175b9126ff8bdc9e61 Mon Sep 17 00:00:00 2001 From: Brian Takita Date: Fri, 17 May 2019 01:35:40 -0400 Subject: [PATCH] Rate limiting the concurrent export requests based on the `concurrent` option. Default is 8. --- src/api/export.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/api/export.ts b/src/api/export.ts index 4dac68b1d..5eabbe65b 100644 --- a/src/api/export.ts +++ b/src/api/export.ts @@ -173,7 +173,7 @@ async function _export({ let match; let pattern = //gm; - const promises = []; + const urls = []; while (match = pattern.exec(cleaned)) { const attrs = match[1]; @@ -183,12 +183,14 @@ async function _export({ const url = resolve(base.href, href); if (url.protocol === protocol && url.host === host) { - promises.push(handle(url)); + urls.push(url); } } } - await Promise.all(promises); + for (let i = 0; i < urls.length; i += concurrent) { + await Promise.all(urls.slice(i, i + concurrent).map(handle)); + } } } }