MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / drainWriteQueue

Method drainWriteQueue

source code/utils/sessionStorage.ts:647–688  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers 2

scheduleDrainMethod · 0.95
flushMethod · 0.95

Calls 3

appendToFileMethod · 0.95
jsonStringifyFunction · 0.85
deleteMethod · 0.80

Tested by

no test coverage detected