* Start the background subscription loop.
()
| 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. |
no test coverage detected