()
| 643 | } |
| 644 | |
| 645 | private async drainWriteQueue(): Promise<void> { |
| 646 | for (const [filePath, queue] of this.writeQueues) { |
| 647 | if (queue.length === 0) { |
| 648 | continue |
| 649 | } |
| 650 | const batch = queue.splice(0) |
| 651 | |
| 652 | let content = '' |
| 653 | const resolvers: Array<() => void> = [] |
| 654 | |
| 655 | for (const { entry, resolve } of batch) { |
| 656 | const line = jsonStringify(entry) + '\n' |
| 657 | |
| 658 | if (content.length + line.length >= this.MAX_CHUNK_BYTES) { |
| 659 | // Flush chunk and resolve its entries before starting a new one |
| 660 | await this.appendToFile(filePath, content) |
| 661 | for (const r of resolvers) { |
| 662 | r() |
| 663 | } |
| 664 | resolvers.length = 0 |
| 665 | content = '' |
| 666 | } |
| 667 | |
| 668 | content += line |
| 669 | resolvers.push(resolve) |
| 670 | } |
| 671 | |
| 672 | if (content.length > 0) { |
| 673 | await this.appendToFile(filePath, content) |
| 674 | for (const r of resolvers) { |
| 675 | r() |
| 676 | } |
| 677 | } |
| 678 | } |
| 679 | |
| 680 | // Clean up empty queues |
| 681 | for (const [filePath, queue] of this.writeQueues) { |
| 682 | if (queue.length === 0) { |
| 683 | this.writeQueues.delete(filePath) |
| 684 | } |
| 685 | } |
| 686 | } |
| 687 | |
| 688 | resetSessionFile(): void { |
| 689 | this.sessionFile = null |
no test coverage detected