✨ Change LIFO to FIFO to preserve task order
This commit is contained in:
parent
064e7be78b
commit
758e69ba27
1 changed files with 5 additions and 4 deletions
|
@ -1,7 +1,8 @@
|
|||
export default function taskManager(tasks: Array<() => Promise<void>>, maxConcurrentTasks: number): Promise<any[]> {
|
||||
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<void>>, maxConcur
|
|||
}
|
||||
} else {
|
||||
//If there is at least one task left, complete it
|
||||
const curTask = remainingTasks.pop() as () => Promise<void>;
|
||||
const curTaskIndex = remainingTasks.length;
|
||||
const curTask = remainingTasks.shift() as () => Promise<void>;
|
||||
const curTaskIndex = origLength - remainingTasks.length;
|
||||
currentlyRunningTasks += 1;
|
||||
curTask().then(function(...result) {
|
||||
returnValues[curTaskIndex] = result;
|
||||
|
|
Loading…
Reference in a new issue