🐛 Fix bug causing task manager to exit early

This commit is contained in:
C-3PO 2018-09-14 06:14:46 +02:00
parent 19f00442b5
commit a7532a92af
Signed by: c3po
GPG key ID: 62993C4BB4D86F24
2 changed files with 5 additions and 4 deletions

View file

@ -175,7 +175,7 @@ export default async function getPatch({ product, from, to, sourceDirectory, tar
} }
//run tasks //run tasks
taskManager(tasks, 5); await taskManager(tasks, 5);
//TODO: add option to delete downloaded files once patching is complete //TODO: add option to delete downloaded files once patching is complete
} }

View file

@ -1,17 +1,18 @@
export default function taskManager(tasks: Array<() => Promise<void>>, maxConcurrentTasks: number): Promise<void> { export default function taskManager(tasks: Array<() => Promise<void>>, maxConcurrentTasks: number): Promise<void> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const remainingTasks = tasks; const remainingTasks = tasks;
//const currentlyRunningTasks: Array<Promise<void>> = []; let currentlyRunningTasks = 0;
const startNewTask = () => { const startNewTask = () => {
if (remainingTasks.length === 0) { if (remainingTasks.length === 0 && currentlyRunningTasks === 0) {
return resolve(); return resolve();
} }
const curTask = remainingTasks.pop() as () => Promise<void>; const curTask = remainingTasks.pop() as () => Promise<void>;
const curPromise = curTask(); const curPromise = curTask();
//currentlyRunningTasks.push(curPromise); currentlyRunningTasks += 1;
curPromise.then(() => { curPromise.then(() => {
currentlyRunningTasks -= 1;
return startNewTask(); return startNewTask();
}); });
}; };