MCPcopy
hub / github.com/TanStack/ai / startSubscription

Method startSubscription

packages/ai-client/src/chat-client.ts:638–666  ·  view source on GitHub ↗

* Start the background subscription loop.

()

Source from the content-addressed store, hash-verified

636 * Start the background subscription loop.
637 */
638 private startSubscription(): void {
639 this.subscriptionAbortController = new AbortController()
640 const signal = this.subscriptionAbortController.signal
641
642 this.consumeSubscription(signal)
643 .catch((err) => {
644 if (err instanceof Error && err.name !== 'AbortError') {
645 this.setConnectionStatus('error')
646 this.resetSessionGenerating()
647 this.setIsSubscribed(false)
648 this.reportStreamError(err)
649 }
650 // Resolve pending processing so streamResponse doesn't hang
651 this.resolveProcessing()
652 })
653 .finally(() => {
654 // Ignore stale loops that were superseded by a restart.
655 if (this.subscriptionAbortController?.signal !== signal) {
656 return
657 }
658 this.subscriptionAbortController = null
659 if (!signal.aborted && this.isSubscribed) {
660 this.setIsSubscribed(false)
661 if (this.connectionStatus !== 'error') {
662 this.setConnectionStatus('disconnected')
663 }
664 }
665 })
666 }
667
668 /**
669 * Consume chunks from the connection subscription.

Callers 1

subscribeMethod · 0.95

Calls 6

consumeSubscriptionMethod · 0.95
setConnectionStatusMethod · 0.95
setIsSubscribedMethod · 0.95
reportStreamErrorMethod · 0.95
resolveProcessingMethod · 0.95

Tested by

no test coverage detected