From 822b7d3b2e82ae0c437c2187b2af7af4f4c07b16 Mon Sep 17 00:00:00 2001 From: C-3PO Date: Fri, 14 Sep 2018 06:22:55 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20task=20manager?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ssn/patcher-installer/taskManager.ts | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/ssn/patcher-installer/taskManager.ts b/src/ssn/patcher-installer/taskManager.ts index fcc8451..b145b35 100644 --- a/src/ssn/patcher-installer/taskManager.ts +++ b/src/ssn/patcher-installer/taskManager.ts @@ -4,17 +4,21 @@ export default function taskManager(tasks: Array<() => Promise>, maxConcur let currentlyRunningTasks = 0; const startNewTask = () => { - if (remainingTasks.length === 0 && currentlyRunningTasks === 0) { - return resolve(); + //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; + const curPromise = curTask(); + currentlyRunningTasks += 1; + curPromise.then(() => { + currentlyRunningTasks -= 1; + return startNewTask(); + }); } - - const curTask = remainingTasks.pop() as () => Promise; - const curPromise = curTask(); - currentlyRunningTasks += 1; - curPromise.then(() => { - currentlyRunningTasks -= 1; - return startNewTask(); - }); }; for (let i = 0; i < maxConcurrentTasks; i += 1) {