MCPcopy Create free account
hub / github.com/HELPMEEADICE/doge-code / drainWriteQueue

Method drainWriteQueue

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

Source from the content-addressed store, hash-verified

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

Callers 2

scheduleDrainMethod · 0.95
flushMethod · 0.95

Calls 3

appendToFileMethod · 0.95
jsonStringifyFunction · 0.85
deleteMethod · 0.65

Tested by

no test coverage detected