diff --git a/lib/BaseDownloadController.js b/lib/BaseDownloadController.js index 736d23a..b2ed8cf 100644 --- a/lib/BaseDownloadController.js +++ b/lib/BaseDownloadController.js @@ -19,6 +19,7 @@ const yaml = require('js-yaml'); const fs = require('fs-extra'); const hash = require('object-hash'); const clone = require('clone'); +const pLimit = require('p-limit'); const CompositeController = require('./CompositeController'); @@ -28,6 +29,11 @@ module.exports = class BaseDownloadController extends CompositeController { constructor(params) { params.finalizerString = params.finalizerString || 'children.downloads.deploy.razee.io'; super(params); + this._limit = pLimit(5); + } + + get limit() { + return this._limit; } async added() { @@ -156,21 +162,25 @@ module.exports = class BaseDownloadController extends CompositeController { if (Array.isArray(file)) { let error; let res = await Promise.all(file.map(async f => { - try { - return await this._decomposeFile(f); - } catch (e) { - error = error || e; - } + return this.limit(async () => { + try { + return await this._decomposeFile(f); + } catch (e) { + error = error || e; + } + }); })); return error ? Promise.reject(error) : res; } else if (kind.toLowerCase() == 'list' && Array.isArray(items)) { let error; let res = await Promise.all(items.map(async f => { - try { - return await this._decomposeFile(f); - } catch (e) { - error = error || e; - } + return this.limit(async () => { + try { + return await this._decomposeFile(f); + } catch (e) { + error = error || e; + } + }); })); return error ? Promise.reject(error) : res; } else if (file) {