MCPcopy
hub / github.com/coder/mux / schedulePartialWrite

Method schedulePartialWrite

src/node/services/streamManager.ts:731–753  ·  view source on GitHub ↗

* Write the current partial message to disk (throttled by mtime) * Ensures writes happen during rapid streaming (crash-resilient)

(
    workspaceId: WorkspaceId,
    streamInfo: WorkspaceStreamInfo
  )

Source from the content-addressed store, hash-verified

729 * Ensures writes happen during rapid streaming (crash-resilient)
730 */
731 private async schedulePartialWrite(
732 workspaceId: WorkspaceId,
733 streamInfo: WorkspaceStreamInfo
734 ): Promise<void> {
735 const now = Date.now();
736 const timeSinceLastWrite = now - streamInfo.lastPartialWriteTime;
737
738 // If enough time has passed, write immediately
739 if (timeSinceLastWrite >= this.PARTIAL_WRITE_THROTTLE_MS) {
740 await this.flushPartialWrite(workspaceId, streamInfo);
741 return;
742 }
743
744 // Otherwise, schedule write for remaining time (fire-and-forget for scheduled writes)
745 if (streamInfo.partialWriteTimer) {
746 clearTimeout(streamInfo.partialWriteTimer);
747 }
748
749 const remainingTime = this.PARTIAL_WRITE_THROTTLE_MS - timeSinceLastWrite;
750 streamInfo.partialWriteTimer = setTimeout(() => {
751 void this.flushPartialWrite(workspaceId, streamInfo);
752 }, remainingTime);
753 }
754
755 private async awaitPendingPartialWrite(streamInfo: WorkspaceStreamInfo): Promise<void> {
756 if (streamInfo.partialWritePromise) {

Callers 3

appendPartAndEmitMethod · 0.95
emitNestedToolEventMethod · 0.95

Calls 1

flushPartialWriteMethod · 0.95

Tested by

no test coverage detected