()
| 689 | } |
| 690 | |
| 691 | private async drainWriteQueue(): Promise<void> { |
| 692 | for (const [filePath, queue] of this.writeQueues) { |
| 693 | if (queue.length === 0) { |
| 694 | continue |
| 695 | } |
| 696 | const batch = queue.splice(0) |
| 697 | |
| 698 | let content = '' |
| 699 | const resolvers: Array<() => void> = [] |
| 700 | |
| 701 | for (const { entry, resolve } of batch) { |
| 702 | const line = jsonStringify(entry) + '\n' |
| 703 | |
| 704 | if (content.length + line.length >= this.MAX_CHUNK_BYTES) { |
| 705 | // Flush chunk and resolve its entries before starting a new one |
| 706 | await this.appendToFile(filePath, content) |
| 707 | for (const r of resolvers) { |
| 708 | r() |
| 709 | } |
| 710 | resolvers.length = 0 |
| 711 | content = '' |
| 712 | } |
| 713 | |
| 714 | content += line |
| 715 | resolvers.push(resolve) |
| 716 | } |
| 717 | |
| 718 | if (content.length > 0) { |
| 719 | await this.appendToFile(filePath, content) |
| 720 | for (const r of resolvers) { |
| 721 | r() |
| 722 | } |
| 723 | } |
| 724 | } |
| 725 | |
| 726 | // Clean up empty queues |
| 727 | for (const [filePath, queue] of this.writeQueues) { |
| 728 | if (queue.length === 0) { |
| 729 | this.writeQueues.delete(filePath) |
| 730 | } |
| 731 | } |
| 732 | } |
| 733 | |
| 734 | resetSessionFile(): void { |
| 735 | this.sessionFile = null |
no test coverage detected