CEC-4499: add bulk update configs support (#357)

* add taskRunner util

* add bulk update config flow
This commit is contained in:
Tristan Timblin
2023-06-14 13:53:32 -04:00
committed by GitHub
parent a68c00b4ad
commit de1a5dcd2d
11 changed files with 621 additions and 7 deletions

36
src/utils/taskRunner.js Normal file
View File

@@ -0,0 +1,36 @@
export default class TaskRunner {
constructor(concurrencyLimit = 1) {
this.queue = [];
this.running = 0;
this.concurrencyLimit = concurrencyLimit;
}
execute() {
if (this.running >= this.concurrencyLimit || this.queue.length === 0) {
return;
}
const task = this.queue.shift();
this.running += 1;
task();
}
async push(fn) {
return new Promise((resolve, reject) => {
const task = async () => {
try {
const result = await fn();
resolve(result);
} catch (error) {
reject(error);
} finally {
this.running -= 1;
this.execute();
}
}
this.queue.push(task);
this.execute();
});
}
}