(chunk: string)
| 17 | } |
| 18 | |
| 19 | push(chunk: string): void { |
| 20 | this.buffer += chunk; |
| 21 | |
| 22 | if (this.rafId !== null) return; // rAF already scheduled |
| 23 | |
| 24 | const now = performance.now(); |
| 25 | const timeSinceLast = now - this.lastFlushTime; |
| 26 | |
| 27 | if (timeSinceLast >= this.maxDelay) { |
| 28 | // Flush is overdue — do it synchronously to avoid latency buildup |
| 29 | this.flush(); |
| 30 | } else { |
| 31 | this.rafId = requestAnimationFrame(() => { |
| 32 | this.rafId = null; |
| 33 | this.flush(); |
| 34 | }); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | flush(): void { |
| 39 | if (!this.buffer) return; |
no test coverage detected