From 758e69ba27b824df938df5618fde837b7a6fc7d9 Mon Sep 17 00:00:00 2001 From: C-3PO Date: Fri, 16 Nov 2018 03:07:17 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Change=20LIFO=20to=20FIFO=20to=20pr?= =?UTF-8?q?eserve=20task=20order?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ssn/installation/taskManager.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ssn/installation/taskManager.ts b/src/ssn/installation/taskManager.ts index 710ecfa..deae0b7 100644 --- a/src/ssn/installation/taskManager.ts +++ b/src/ssn/installation/taskManager.ts @@ -1,7 +1,8 @@ export default function taskManager(tasks: Array<() => Promise>, maxConcurrentTasks: number): Promise { return new Promise(function(resolve, reject) { - const returnValues = Array(tasks.length); - const remainingTasks = tasks; + const origLength = tasks.length; + const returnValues = Array(origLength); + const remainingTasks = tasks.slice(); let currentlyRunningTasks = 0; const startNewTask = function() { @@ -12,8 +13,8 @@ export default function taskManager(tasks: Array<() => Promise>, maxConcur } } else { //If there is at least one task left, complete it - const curTask = remainingTasks.pop() as () => Promise; - const curTaskIndex = remainingTasks.length; + const curTask = remainingTasks.shift() as () => Promise; + const curTaskIndex = origLength - remainingTasks.length; currentlyRunningTasks += 1; curTask().then(function(...result) { returnValues[curTaskIndex] = result;