MCPcopy Index your code
hub / github.com/codeaashu/claude-code / drainWriteQueue

Method drainWriteQueue

src/utils/sessionStorage.ts:645–686  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers 2

scheduleDrainMethod · 0.95
flushMethod · 0.95

Calls 6

appendToFileMethod · 0.95
jsonStringifyFunction · 0.85
spliceMethod · 0.80
deleteMethod · 0.65
rFunction · 0.50
pushMethod · 0.45

Tested by

no test coverage detected