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;