dino-express
Version:
DinO enabled REST framework based on express
34 lines • 968 B
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EventQueue = void 0;
class EventQueue {
batchSize;
eventEmitter;
queue;
accept;
constructor(eventEmitter, batchSize = 1) {
this.queue = [];
this.accept = true;
this.batchSize = batchSize;
this.eventEmitter = eventEmitter;
}
add(applicationEvent) {
if (!this.accept) {
return false;
}
const currentLength = this.queue.push(applicationEvent);
if (currentLength >= this.batchSize) {
const eventsToEmit = this.queue.splice(0, this.batchSize);
void this.eventEmitter.emit(eventsToEmit);
}
return true;
}
async flush() {
this.accept = false;
await this.eventEmitter.emit(this.queue);
this.queue.splice(0);
this.accept = true;
}
}
exports.EventQueue = EventQueue;
//# sourceMappingURL=EventQueue.js.map