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(); }); };