()
| 58 | // short. Timer-based flushes already run outside user code paths so they |
| 59 | // stay synchronous. |
| 60 | function flushDeferred(): void { |
| 61 | if (pendingOverflow) { |
| 62 | // A previous overflow write is still queued. Coalesce into it to |
| 63 | // preserve ordering — writes land in a single setImmediate-ordered batch. |
| 64 | pendingOverflow.push(...buffer) |
| 65 | buffer = [] |
| 66 | bufferBytes = 0 |
| 67 | clearTimer() |
| 68 | return |
| 69 | } |
| 70 | const detached = buffer |
| 71 | buffer = [] |
| 72 | bufferBytes = 0 |
| 73 | clearTimer() |
| 74 | pendingOverflow = detached |
| 75 | setImmediate(() => { |
| 76 | const toWrite = pendingOverflow |
| 77 | pendingOverflow = null |
| 78 | if (toWrite) writeFn(toWrite.join('')) |
| 79 | }) |
| 80 | } |
| 81 | |
| 82 | return { |
| 83 | write(content: string): void { |
no test coverage detected