Initial Work

This commit is contained in:
Michael Fabian 'Xaymar' Dirks
2020-10-25 18:08:58 +01:00
commit 43952dd162
11 changed files with 1186 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
class poolqueue {
constructor() {
this.queues = new Array();
this.index = {};
this.costs = {};
}
clear() {
this.queues = new Array();
this.index = {};
this.costs = {};
}
push(name, command, cost) {
if (!this.index[name]) {
this.index[name] = 0;
}
if (!this.costs[name]) {
this.costs[name] = 0;
}
// Make sure Queue exists
if (!this.queues[this.index[name]]) {
this.queues[this.index[name]] = new Array();
if (global.debug) console.debug(`${name}: Created new pool.`);
}
// Push the new command.
this.queues[this.index[name]] = this.queues[this.index[name]].concat(command);
this.costs[name] += cost;
if (this.costs[name] > 1.0) {
this.index[name]++;
if (global.debug) console.debug(`${name}: Incremented index to ${this.index[name]} due to cost ${this.costs[name]}.`);
this.costs[name] = 0.0;
}
}
finalize() {
return this.queues;
}
}
module.exports = poolqueue;