@maximai/maxim-js
Version:
Maxim AI JS SDK. Visit https://getmaxim.ai for more info.
36 lines • 957 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Queue = void 0;
class Queue {
constructor(maxSize = 10000) {
this.storage = new Array();
this.maxSize = maxSize;
}
enqueue(item) {
if (this.storage.length >= this.maxSize) {
// remove the oldest item
this.storage.shift();
}
this.storage.push(item);
}
enqueueAll(items) {
if (this.storage.length + items.length > this.maxSize) {
// remove the oldest items
this.storage.splice(0, items.length - this.maxSize);
}
this.storage.push(...items);
}
dequeue() {
return this.storage.shift();
}
dequeueAll() {
const items = this.storage;
this.storage = new Array();
return items;
}
get size() {
return this.storage.length;
}
}
exports.Queue = Queue;
//# sourceMappingURL=queue.js.map