class Logger {
constructor() {
this.logs = [];
this.p = Promise.withResolvers();
}
log(...args) {
console.log(...args);
this.logs.push({ t: Date.now(), l: "log", c: args });
setTimeout(() => this.p?.resolve(), 0);
}
clear() {
this.logs = [];
setTimeout(() => this.p?.resolve(), 0);
}
async *display(fn = (v) => v) {
while (true) {
yield this.logs.map(fn);
await this.p.promise;
this.p = Promise.withResolvers();
}
}
}