MCPcopy Create free account
hub / github.com/Noumena-Network/code / drainWriteQueue

Method drainWriteQueue

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

Source from the content-addressed store, hash-verified

724 }
725
726 private async drainWriteQueue(): Promise<void> {
727 for (const [filePath, queue] of this.writeQueues) {
728 if (queue.length === 0) {
729 continue
730 }
731 const batch = queue.splice(0)
732
733 let content = ''
734 const resolvers: Array<() => void> = []
735
736 for (const { entry, resolve } of batch) {
737 const line = jsonStringify(entry) + '\n'
738
739 if (content.length + line.length >= this.MAX_CHUNK_BYTES) {
740 // Flush chunk and resolve its entries before starting a new one
741 await this.appendToFile(filePath, content)
742 for (const r of resolvers) {
743 r()
744 }
745 resolvers.length = 0
746 content = ''
747 }
748
749 content += line
750 resolvers.push(resolve)
751 }
752
753 if (content.length > 0) {
754 await this.appendToFile(filePath, content)
755 for (const r of resolvers) {
756 r()
757 }
758 }
759 }
760
761 // Clean up empty queues
762 for (const [filePath, queue] of this.writeQueues) {
763 if (queue.length === 0) {
764 this.writeQueues.delete(filePath)
765 }
766 }
767 }
768
769 resetSessionFile(): void {
770 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