tinycoll
Version:
A minimal reactive document store with Mongo-like querying, reactivity, TTL support, and optional persistence.
33 lines (32 loc) • 787 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PromiseQueue = void 0;
class PromiseQueue {
#queue = [];
#isRunning = false;
push(fn) {
this.#queue.push(fn);
void this.#run();
}
get size() {
return this.#queue.length;
}
async #run() {
if (this.#isRunning)
return;
this.#isRunning = true;
while (this.#queue.length > 0) {
const job = this.#queue.shift();
if (!job)
continue;
try {
await job();
}
catch (err) {
console.error('PromiseQueue error:', err);
}
}
this.#isRunning = false;
}
}
exports.PromiseQueue = PromiseQueue;