@devexcelsior/session-ring
Version:
25 lines (24 loc) • 764 B
JavaScript
;
// Formerly © 2025 Curt Puckett / DevExcelsior – all rights waived under the Unlicense.
// This code is now public domain. No rights reserved. No attribution required.
Object.defineProperty(exports, "__esModule", { value: true });
exports.SessionRing = void 0;
class SessionRing {
constructor(maxSnapshots = 10) {
this.buffer = new Array(maxSnapshots);
this.max = maxSnapshots;
this.cursor = 0;
}
write(snapshot) {
this.buffer[this.cursor] = snapshot;
this.cursor = (this.cursor + 1) % this.max;
}
read() {
return [...this.buffer].filter(Boolean);
}
clear() {
this.buffer = new Array(this.max);
this.cursor = 0;
}
}
exports.SessionRing = SessionRing;