🐛 Fix task manager

This commit is contained in:
C-3PO 2018-09-14 06:22:55 +02:00
parent a7532a92af
commit 822b7d3b2e
Signed by: c3po
GPG key ID: 62993C4BB4D86F24

View file

@ -4,10 +4,13 @@ export default function taskManager(tasks: Array<() => Promise<void>>, maxConcur
let currentlyRunningTasks = 0;
const startNewTask = () => {
if (remainingTasks.length === 0 && currentlyRunningTasks === 0) {
//Exit if we completed all tasks
if (remainingTasks.length === 0) {
if (currentlyRunningTasks === 0) {
return resolve();
}
} else {
//If there is at least one task left, complete it
const curTask = remainingTasks.pop() as () => Promise<void>;
const curPromise = curTask();
currentlyRunningTasks += 1;
@ -15,6 +18,7 @@ export default function taskManager(tasks: Array<() => Promise<void>>, maxConcur
currentlyRunningTasks -= 1;
return startNewTask();
});
}
};
for (let i = 0; i < maxConcurrentTasks; i += 1) {