{"/mnt/d/Projecten/Promise-parallel-throttle/src/throttle.ts": {"path":"/mnt/d/Projecten/Promise-parallel-throttle/src/throttle.ts","statementMap":{"0":{"start":{"line":1,"column":13},"end":{"line":1,"column":42}},"1":{"start":{"line":1,"column":42},"end":{"line":1,"column":55}},"2":{"start":{"line":2,"column":0},"end":{"line":2,"column":62}},"3":{"start":{"line":3,"column":18},"end":{"line":3,"column":19}},"4":{"start":{"line":17,"column":27},"end":{"line":21,"column":1}},"5":{"start":{"line":18,"column":4},"end":{"line":20,"column":7}},"6":{"start":{"line":19,"column":8},"end":{"line":19,"column":53}},"7":{"start":{"line":22,"column":22},"end":{"line":26,"column":1}},"8":{"start":{"line":34,"column":4},"end":{"line":110,"column":7}},"9":{"start":{"line":35,"column":24},"end":{"line":35,"column":67}},"10":{"start":{"line":36,"column":21},"end":{"line":46,"column":9}},"11":{"start":{"line":47,"column":8},"end":{"line":49,"column":9}},"12":{"start":{"line":48,"column":12},"end":{"line":48,"column":35}},"13":{"start":{"line":50,"column":25},"end":{"line":50,"column":30}},"14":{"start":{"line":51,"column":31},"end":{"line":51,"column":32}},"15":{"start":{"line":52,"column":26},"end":{"line":75,"column":9}},"16":{"start":{"line":53,"column":12},"end":{"line":53,"column":35}},"17":{"start":{"line":54,"column":12},"end":{"line":74,"column":13}},"18":{"start":{"line":55,"column":16},"end":{"line":69,"column":19}},"19":{"start":{"line":56,"column":20},"end":{"line":56,"column":59}},"20":{"start":{"line":57,"column":20},"end":{"line":57,"column":55}},"21":{"start":{"line":58,"column":20},"end":{"line":58,"column":44}},"22":{"start":{"line":59,"column":20},"end":{"line":59,"column":31}},"23":{"start":{"line":61,"column":20},"end":{"line":61,"column":54}},"24":{"start":{"line":62,"column":20},"end":{"line":62,"column":55}},"25":{"start":{"line":63,"column":20},"end":{"line":63,"column":44}},"26":{"start":{"line":64,"column":20},"end":{"line":67,"column":21}},"27":{"start":{"line":65,"column":24},"end":{"line":65,"column":42}},"28":{"start":{"line":66,"column":24},"end":{"line":66,"column":46}},"29":{"start":{"line":68,"column":20},"end":{"line":68,"column":31}},"30":{"start":{"line":72,"column":16},"end":{"line":72,"column":34}},"31":{"start":{"line":73,"column":16},"end":{"line":73,"column":123}},"32":{"start":{"line":76,"column":23},"end":{"line":91,"column":9}},"33":{"start":{"line":78,"column":12},"end":{"line":80,"column":13}},"34":{"start":{"line":79,"column":16},"end":{"line":79,"column":23}},"35":{"start":{"line":81,"column":12},"end":{"line":81,"column":32}},"36":{"start":{"line":82,"column":12},"end":{"line":84,"column":13}},"37":{"start":{"line":83,"column":16},"end":{"line":83,"column":51}},"38":{"start":{"line":85,"column":12},"end":{"line":87,"column":13}},"39":{"start":{"line":86,"column":16},"end":{"line":86,"column":39}},"40":{"start":{"line":88,"column":12},"end":{"line":90,"column":13}},"41":{"start":{"line":89,"column":16},"end":{"line":89,"column":45}},"42":{"start":{"line":92,"column":23},"end":{"line":105,"column":9}},"43":{"start":{"line":94,"column":12},"end":{"line":104,"column":23}},"44":{"start":{"line":95,"column":16},"end":{"line":103,"column":17}},"45":{"start":{"line":97,"column":20},"end":{"line":97,"column":39}},"46":{"start":{"line":100,"column":20},"end":{"line":100,"column":51}},"47":{"start":{"line":101,"column":20},"end":{"line":101,"column":62}},"48":{"start":{"line":102,"column":20},"end":{"line":102,"column":31}},"49":{"start":{"line":107,"column":8},"end":{"line":109,"column":9}},"50":{"start":{"line":108,"column":12},"end":{"line":108,"column":41}},"51":{"start":{"line":112,"column":0},"end":{"line":112,"column":18}},"52":{"start":{"line":120,"column":4},"end":{"line":131,"column":7}},"53":{"start":{"line":121,"column":8},"end":{"line":130,"column":11}},"54":{"start":{"line":122,"column":12},"end":{"line":122,"column":40}},"55":{"start":{"line":124,"column":12},"end":{"line":129,"column":13}},"56":{"start":{"line":125,"column":16},"end":{"line":125,"column":30}},"57":{"start":{"line":128,"column":16},"end":{"line":128,"column":68}},"58":{"start":{"line":140,"column":20},"end":{"line":140,"column":84}},"59":{"start":{"line":141,"column":4},"end":{"line":141,"column":40}},"60":{"start":{"line":143,"column":0},"end":{"line":143,"column":20}},"61":{"start":{"line":151,"column":20},"end":{"line":151,"column":66}},"62":{"start":{"line":152,"column":4},"end":{"line":152,"column":40}},"63":{"start":{"line":154,"column":0},"end":{"line":154,"column":18}}},"fnMap":{"0":{"name":"(anonymous_0)","decl":{"start":{"line":17,"column":27},"end":{"line":17,"column":28}},"loc":{"start":{"line":17,"column":52},"end":{"line":21,"column":1}},"line":17},"1":{"name":"(anonymous_1)","decl":{"start":{"line":18,"column":23},"end":{"line":18,"column":24}},"loc":{"start":{"line":18,"column":50},"end":{"line":20,"column":5}},"line":18},"2":{"name":"raw","decl":{"start":{"line":33,"column":9},"end":{"line":33,"column":12}},"loc":{"start":{"line":33,"column":29},"end":{"line":111,"column":1}},"line":33},"3":{"name":"(anonymous_3)","decl":{"start":{"line":34,"column":23},"end":{"line":34,"column":24}},"loc":{"start":{"line":34,"column":50},"end":{"line":110,"column":5}},"line":34},"4":{"name":"(anonymous_4)","decl":{"start":{"line":52,"column":26},"end":{"line":52,"column":27}},"loc":{"start":{"line":52,"column":43},"end":{"line":75,"column":9}},"line":52},"5":{"name":"(anonymous_5)","decl":{"start":{"line":55,"column":36},"end":{"line":55,"column":37}},"loc":{"start":{"line":55,"column":58},"end":{"line":60,"column":17}},"line":55},"6":{"name":"(anonymous_6)","decl":{"start":{"line":60,"column":19},"end":{"line":60,"column":20}},"loc":{"start":{"line":60,"column":36},"end":{"line":69,"column":17}},"line":60},"7":{"name":"(anonymous_7)","decl":{"start":{"line":76,"column":23},"end":{"line":76,"column":24}},"loc":{"start":{"line":76,"column":35},"end":{"line":91,"column":9}},"line":76},"8":{"name":"(anonymous_8)","decl":{"start":{"line":92,"column":23},"end":{"line":92,"column":24}},"loc":{"start":{"line":92,"column":40},"end":{"line":105,"column":9}},"line":92},"9":{"name":"(anonymous_9)","decl":{"start":{"line":94,"column":52},"end":{"line":94,"column":53}},"loc":{"start":{"line":94,"column":82},"end":{"line":104,"column":13}},"line":94},"10":{"name":"executeRaw","decl":{"start":{"line":119,"column":9},"end":{"line":119,"column":19}},"loc":{"start":{"line":119,"column":36},"end":{"line":132,"column":1}},"line":119},"11":{"name":"(anonymous_11)","decl":{"start":{"line":120,"column":23},"end":{"line":120,"column":24}},"loc":{"start":{"line":120,"column":50},"end":{"line":131,"column":5}},"line":120},"12":{"name":"(anonymous_12)","decl":{"start":{"line":121,"column":33},"end":{"line":121,"column":34}},"loc":{"start":{"line":121,"column":51},"end":{"line":123,"column":9}},"line":121},"13":{"name":"(anonymous_13)","decl":{"start":{"line":123,"column":11},"end":{"line":123,"column":12}},"loc":{"start":{"line":123,"column":28},"end":{"line":130,"column":9}},"line":123},"14":{"name":"sync","decl":{"start":{"line":139,"column":9},"end":{"line":139,"column":13}},"loc":{"start":{"line":139,"column":30},"end":{"line":142,"column":1}},"line":139},"15":{"name":"all","decl":{"start":{"line":150,"column":9},"end":{"line":150,"column":12}},"loc":{"start":{"line":150,"column":29},"end":{"line":153,"column":1}},"line":150}},"branchMap":{"0":{"loc":{"start":{"line":47,"column":8},"end":{"line":49,"column":9}},"type":"if","locations":[{"start":{"line":47,"column":8},"end":{"line":49,"column":9}},{"start":{"line":47,"column":8},"end":{"line":49,"column":9}}],"line":47},"1":{"loc":{"start":{"line":54,"column":12},"end":{"line":74,"column":13}},"type":"if","locations":[{"start":{"line":54,"column":12},"end":{"line":74,"column":13}},{"start":{"line":54,"column":12},"end":{"line":74,"column":13}}],"line":54},"2":{"loc":{"start":{"line":64,"column":20},"end":{"line":67,"column":21}},"type":"if","locations":[{"start":{"line":64,"column":20},"end":{"line":67,"column":21}},{"start":{"line":64,"column":20},"end":{"line":67,"column":21}}],"line":64},"3":{"loc":{"start":{"line":78,"column":12},"end":{"line":80,"column":13}},"type":"if","locations":[{"start":{"line":78,"column":12},"end":{"line":80,"column":13}},{"start":{"line":78,"column":12},"end":{"line":80,"column":13}}],"line":78},"4":{"loc":{"start":{"line":82,"column":12},"end":{"line":84,"column":13}},"type":"if","locations":[{"start":{"line":82,"column":12},"end":{"line":84,"column":13}},{"start":{"line":82,"column":12},"end":{"line":84,"column":13}}],"line":82},"5":{"loc":{"start":{"line":85,"column":12},"end":{"line":87,"column":13}},"type":"if","locations":[{"start":{"line":85,"column":12},"end":{"line":87,"column":13}},{"start":{"line":85,"column":12},"end":{"line":87,"column":13}}],"line":85},"6":{"loc":{"start":{"line":88,"column":12},"end":{"line":90,"column":13}},"type":"if","locations":[{"start":{"line":88,"column":12},"end":{"line":90,"column":13}},{"start":{"line":88,"column":12},"end":{"line":90,"column":13}}],"line":88},"7":{"loc":{"start":{"line":95,"column":16},"end":{"line":103,"column":17}},"type":"if","locations":[{"start":{"line":95,"column":16},"end":{"line":103,"column":17}},{"start":{"line":95,"column":16},"end":{"line":103,"column":17}}],"line":95},"8":{"loc":{"start":{"line":124,"column":12},"end":{"line":129,"column":13}},"type":"if","locations":[{"start":{"line":124,"column":12},"end":{"line":129,"column":13}},{"start":{"line":124,"column":12},"end":{"line":129,"column":13}}],"line":124}},"s":{"0":1,"1":1,"2":1,"3":1,"4":1,"5":71,"6":71,"7":1,"8":19,"9":19,"10":19,"11":19,"12":1,"13":18,"14":18,"15":18,"16":81,"17":81,"18":78,"19":56,"20":56,"21":56,"22":56,"23":22,"24":22,"25":22,"26":22,"27":7,"28":7,"29":15,"30":3,"31":3,"32":18,"33":75,"34":8,"35":67,"36":67,"37":5,"38":67,"39":11,"40":56,"41":26,"42":18,"43":86,"44":85,"45":81,"46":4,"47":4,"48":4,"49":18,"50":60,"51":1,"52":8,"53":8,"54":4,"55":4,"56":2,"57":2,"58":4,"59":4,"60":1,"61":4,"62":4,"63":1},"f":{"0":71,"1":71,"2":19,"3":19,"4":81,"5":56,"6":22,"7":75,"8":86,"9":85,"10":8,"11":8,"12":4,"13":4,"14":4,"15":4},"b":{"0":[1,18],"1":[78,3],"2":[7,15],"3":[8,67],"4":[5,62],"5":[11,56],"6":[26,30],"7":[81,4],"8":[2,2]},"inputSourceMap":{"version":3,"file":"throttle.js","sourceRoot":"","sources":["file:////mnt/d/Projecten/Promise-parallel-throttle/src/throttle.ts"],"names":[],"mappings":";;AAAA,IAAM,WAAW,GAAG,CAAC,CAAC;AAqBtB;;;;;;;;;;;;GAYG;AACH,IAAM,oBAAoB,GAAkB,UAAI,MAAiB,EAAE,KAAe;IAC9E,MAAM,CAAC,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;QAC/B,OAAO,CAAC,MAAM,CAAC,aAAa,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;IACjD,CAAC,CAAC,CAAC;AACP,CAAC,CAAC;AAEF,IAAM,eAAe,GAAG;IACpB,aAAa,EAAE,WAAW;IAC1B,QAAQ,EAAE,KAAK;IACf,SAAS,EAAE,oBAAoB;CAClC,CAAC;AAMF;;;;;GAKG;AACH,aAAuB,KAAe,EAAE,OAAiB;IACrD,MAAM,CAAC,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;QAC/B,IAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,eAAe,EAAE,OAAO,CAAC,CAAC;QAC9D,IAAM,MAAM,GAAc;YACtB,UAAU,EAAE,CAAC;YACb,aAAa,EAAE,CAAC;YAChB,cAAc,EAAE,CAAC;YACjB,cAAc,EAAE,CAAC;YACjB,qBAAqB,EAAE,CAAC;YACxB,eAAe,EAAE,EAAE;YACnB,eAAe,EAAE,EAAE;YACnB,sBAAsB,EAAE,EAAE;YAC1B,WAAW,EAAE,EAAE;SAClB,CAAC;QAEF,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC;YACrB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC3B,CAAC;QAED,IAAI,UAAU,GAAG,KAAK,CAAC;QACvB,IAAI,gBAAgB,GAAG,CAAC,CAAC;QACzB,IAAM,WAAW,GAAG,UAAC,KAAa;YAC9B,MAAM,CAAC,aAA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AC,UAAC,OAAO,EAAE,MAAM;QAC/B,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,IAAI,CACpB,UAAC,MAAiB;YACd,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;QAChC,CAAC,EACD,UAAC,KAAwB;YACrB,EAAE,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC;gBACzB,MAAM,CAAC,KAAK,CAAC,CAAC;YAClB,CAAC;YAAC,IAAI,CAAC,CAAC;gBACJ,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACxD,CAAC;QACL,CAAC,CACJ,CAAC;IACN,CAAC,CAAC,CAAC;AACP,CAAC;AAED;;;;;GAKG;AACH,cAAwB,KAAe,EAAE,OAAiB;IACtD,IAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,aAAa,EAAE,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC;IACnF,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;AACxC,CAAC;AAHD,oBAGC;AAED;;;;;GAKG;AACH,aAAuB,KAAe,EAAE,OAAiB;IACrD,IAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC;IACjE,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;AACxC,CAAC;AAHD,kBAGC","sourcesContent":["const DEFAULT_MAX = 5;\r\n\r\nexport interface Result {\r\n amountDone: number;\r\n amountStarted: number;\r\n amountResolved: number;\r\n amountRejected: number;\r\n amountNextCheckFalsey: number;\r\n rejectedIndexes: number[];\r\n resolvedIndexes: number[];\r\n nextCheckFalseyIndexes: number[];\r\n taskResults: T[];\r\n}\r\n\r\nexport interface Options {\r\n maxInProgress?: number;\r\n failFast?: boolean;\r\n progressCallback?: (result: Result) => void;\r\n nextCheck?: nextTaskCheck;\r\n}\r\n\r\n/**\r\n * Default checker which validates if a next task should begin.\r\n * This can be overwritten to write own checks for example checking the amount\r\n * of used ram and waiting till the ram is low enough for a next task.\r\n *\r\n * It should always resolve with a boolean, either `true` to start a next task\r\n * or `false` to stop executing a new task.\r\n *\r\n * If this method rejects, the error will propagate to the caller\r\n * @param status\r\n * @param tasks\r\n * @returns {Promise}\r\n */\r\nconst defaultNextTaskCheck: nextTaskCheck = (status: Result, tasks: Tasks): Promise => {\r\n return new Promise((resolve, reject) => {\r\n resolve(status.amountStarted < tasks.length);\r\n });\r\n};\r\n\r\nconst DEFAULT_OPTIONS = {\r\n maxInProgress: DEFAULT_MAX,\r\n failFast: false,\r\n nextCheck: defaultNextTaskCheck\r\n};\r\n\r\nexport type Task = () => Promise;\r\nexport type Tasks = Array>;\r\nexport type nextTaskCheck = (status: Result, tasks: Tasks) => Promise;\r\n\r\n/**\r\n * Raw throttle function, which can return extra meta data.\r\n * @param tasks required array of tasks to be executed\r\n * @param options Options object\r\n * @returns {Promise}\r\n */\r\nexport function raw(tasks: Tasks, options?: Options): Promise> {\r\n return new Promise((resolve, reject) => {\r\n const myOptions = Object.assign({}, DEFAULT_OPTIONS, options);\r\n const result: Result = {\r\n amountDone: 0,\r\n amountStarted: 0,\r\n amountResolved: 0,\r\n amountRejected: 0,\r\n amountNextCheckFalsey: 0,\r\n rejectedIndexes: [],\r\n resolvedIndexes: [],\r\n nextCheckFalseyIndexes: [],\r\n taskResults: []\r\n };\r\n\r\n if (tasks.length === 0) {\r\n return resolve(result);\r\n }\r\n\r\n let failedFast = false;\r\n let currentTaskIndex = 0;\r\n const executeTask = (index: number) => {\r\n result.amountStarted++;\r\n\r\n if (typeof tasks[index] === 'function') {\r\n tasks[index]().then(\r\n taskResult => {\r\n result.taskResults[index] = taskResult;\r\n result.resolvedIndexes.push(index);\r\n result.amountResolved++;\r\n taskDone();\r\n },\r\n error => {\r\n result.taskResults[index] = error;\r\n result.rejectedIndexes.push(index);\r\n result.amountRejected++;\r\n if (myOptions.failFast === true) {\r\n failedFast = true;\r\n return reject(result);\r\n }\r\n taskDone();\r\n }\r\n );\r\n } else {\r\n failedFast = true;\r\n return reject(\r\n new Error('tasks[' + index + ']: ' + tasks[index] + ', is supposed to be of type function')\r\n );\r\n }\r\n };\r\n\r\n const taskDone = () => {\r\n //make sure no more tasks are spawned when we failedFast\r\n if (failedFast === true) {\r\n return;\r\n }\r\n\r\n result.amountDone++;\r\n if (typeof (myOptions as Options).progressCallback === 'function') {\r\n (myOptions as any).progressCallback(result);\r\n }\r\n if (result.amountDone === tasks.length) {\r\n return resolve(result);\r\n }\r\n if (currentTaskIndex < tasks.length) {\r\n nextTask(currentTaskIndex++);\r\n }\r\n };\r\n\r\n const nextTask = (index: number) => {\r\n //check if we can execute the next task\r\n myOptions.nextCheck(result, tasks).then(canExecuteNextTask => {\r\n if (canExecuteNextTask === true) {\r\n //execute it\r\n executeTask(index);\r\n } else {\r\n result.amountNextCheckFalsey++;\r\n result.nextCheckFalseyIndexes.push(index);\r\n taskDone();\r\n }\r\n }, reject);\r\n };\r\n\r\n //spawn the first X task\r\n for (let i = 0; i < Math.min(myOptions.maxInProgress, tasks.length); i++) {\r\n nextTask(currentTaskIndex++);\r\n }\r\n });\r\n}\r\n\r\n/**\r\n * Executes the raw function, but only return the task array\r\n * @param tasks \r\n * @param options \r\n * @returns {Promise}\r\n */\r\nfunction executeRaw(tasks: Tasks, options: Options): Promise {\r\n return new Promise((resolve, reject) => {\r\n raw(tasks, options).then(\r\n (result: Result) => {\r\n resolve(result.taskResults);\r\n },\r\n (error: Error | Result) => {\r\n if (error instanceof Error) {\r\n reject(error);\r\n } else {\r\n reject(error.taskResults[error.rejectedIndexes[0]]);\r\n }\r\n }\r\n );\r\n });\r\n}\r\n\r\n/**\r\n * Simply run all the promises after each other, so in synchronous manner\r\n * @param tasks required array of tasks to be executed\r\n * @param options Options object\r\n * @returns {Promise}\r\n */\r\nexport function sync(tasks: Tasks, options?: Options): Promise {\r\n const myOptions = Object.assign({}, { maxInProgress: 1, failFast: true }, options);\r\n return executeRaw(tasks, myOptions);\r\n}\r\n\r\n/**\r\n * Exposes the same behaviour as Promise.All(), but throttled!\r\n * @param tasks required array of tasks to be executed\r\n * @param options Options object\r\n * @returns {Promise}\r\n */\r\nexport function all(tasks: Tasks, options?: Options): Promise {\r\n const myOptions = Object.assign({}, { failFast: true }, options);\r\n return executeRaw(tasks, myOptions);\r\n}\r\n"]},"_coverageSchema":"332fd63041d2c1bcb487cc26dd0d5f7d97098a6c","hash":"579921541b26caec6f98bdd740b0875053cea541"} }