()
| 657 | } |
| 658 | |
| 659 | private async drainWriteQueue(): Promise<void> { |
| 660 | for (const [filePath, queue] of this.writeQueues) { |
| 661 | if (queue.length === 0) { |
| 662 | continue |
| 663 | } |
| 664 | const batch = queue.splice(0) |
| 665 | |
| 666 | let content = '' |
| 667 | const resolvers: Array<() => void> = [] |
| 668 | |
| 669 | for (const { entry, resolve } of batch) { |
| 670 | const line = jsonStringify(entry) + '\n' |
| 671 | |
| 672 | if (content.length + line.length >= this.MAX_CHUNK_BYTES) { |
| 673 | // Flush chunk and resolve its entries before starting a new one |
| 674 | await this.appendToFile(filePath, content) |
| 675 | for (const r of resolvers) { |
| 676 | r() |
| 677 | } |
| 678 | resolvers.length = 0 |
| 679 | content = '' |
| 680 | } |
| 681 | |
| 682 | content += line |
| 683 | resolvers.push(resolve) |
| 684 | } |
| 685 | |
| 686 | if (content.length > 0) { |
| 687 | await this.appendToFile(filePath, content) |
| 688 | for (const r of resolvers) { |
| 689 | r() |
| 690 | } |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | // Clean up empty queues |
| 695 | for (const [filePath, queue] of this.writeQueues) { |
| 696 | if (queue.length === 0) { |
| 697 | this.writeQueues.delete(filePath) |
| 698 | } |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | resetSessionFile(): void { |
| 703 | this.sessionFile = null |
no test coverage detected