From a7532a92af51df03339cf4a88b6ae290639d606c Mon Sep 17 00:00:00 2001 From: C-3PO Date: Fri, 14 Sep 2018 06:14:46 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20bug=20causing=20task=20man?= =?UTF-8?q?ager=20to=20exit=20early?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ssn/getPatch.ts | 2 +- src/ssn/patcher-installer/taskManager.ts | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ssn/getPatch.ts b/src/ssn/getPatch.ts index d432034..08c2496 100644 --- a/src/ssn/getPatch.ts +++ b/src/ssn/getPatch.ts @@ -175,7 +175,7 @@ export default async function getPatch({ product, from, to, sourceDirectory, tar } //run tasks - taskManager(tasks, 5); + await taskManager(tasks, 5); //TODO: add option to delete downloaded files once patching is complete } diff --git a/src/ssn/patcher-installer/taskManager.ts b/src/ssn/patcher-installer/taskManager.ts index 6c22aa9..fcc8451 100644 --- a/src/ssn/patcher-installer/taskManager.ts +++ b/src/ssn/patcher-installer/taskManager.ts @@ -1,17 +1,18 @@ export default function taskManager(tasks: Array<() => Promise>, maxConcurrentTasks: number): Promise { return new Promise((resolve, reject) => { const remainingTasks = tasks; - //const currentlyRunningTasks: Array> = []; + let currentlyRunningTasks = 0; const startNewTask = () => { - if (remainingTasks.length === 0) { + if (remainingTasks.length === 0 && currentlyRunningTasks === 0) { return resolve(); } const curTask = remainingTasks.pop() as () => Promise; const curPromise = curTask(); - //currentlyRunningTasks.push(curPromise); + currentlyRunningTasks += 1; curPromise.then(() => { + currentlyRunningTasks -= 1; return startNewTask(); }); };