🐛 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
|
//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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue