🐛 Fix bug causing task manager to exit early
This commit is contained in:
parent
19f00442b5
commit
a7532a92af
2 changed files with 5 additions and 4 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
export default function taskManager(tasks: Array<() => Promise<void>>, maxConcurrentTasks: number): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const remainingTasks = tasks;
|
||||
//const currentlyRunningTasks: Array<Promise<void>> = [];
|
||||
let currentlyRunningTasks = 0;
|
||||
|
||||
const startNewTask = () => {
|
||||
if (remainingTasks.length === 0) {
|
||||
if (remainingTasks.length === 0 && currentlyRunningTasks === 0) {
|
||||
return resolve();
|
||||
}
|
||||
|
||||
const curTask = remainingTasks.pop() as () => Promise<void>;
|
||||
const curPromise = curTask();
|
||||
//currentlyRunningTasks.push(curPromise);
|
||||
currentlyRunningTasks += 1;
|
||||
curPromise.then(() => {
|
||||
currentlyRunningTasks -= 1;
|
||||
return startNewTask();
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue