@@ -142,19 +142,19 @@ export class RealtimeHandler {
142142 * Stops the real-time HTTP connection by aborting the in-progress fetch request
143143 * and canceling the stream reader if they exist.
144144 */
145- private closeRealtimeHttpConnection ( ) : void {
146- if ( this . isClosingConnection ) {
145+ private async closeRealtimeHttpConnection ( ) : Promise < void > {
146+ if ( this . isClosingConnection ) {
147147 return ;
148148 }
149149 this . isClosingConnection = true ;
150-
150+
151151 if ( this . reader ) {
152- void this . reader . cancel ( ) ;
152+ await this . reader . cancel ( ) ;
153153 this . reader = undefined ;
154154 }
155155
156156 if ( this . controller ) {
157- this . controller . abort ( ) ;
157+ await this . controller . abort ( ) ;
158158 this . controller = undefined ;
159159 }
160160
@@ -595,8 +595,9 @@ export class RealtimeHandler {
595595 this . setIsHttpConnectionRunning ( false ) ;
596596
597597 // Update backoff metadata if the connection failed in the foreground.
598- const connectionFailed = ! this . isInBackground &&
599- responseCode == null || this . isStatusCodeRetryable ( responseCode ) ;
598+ const connectionFailed =
599+ ! this . isInBackground &&
600+ ( responseCode == null || this . isStatusCodeRetryable ( responseCode ) ) ;
600601
601602 if ( connectionFailed ) {
602603 await this . updateBackoffMetadataWithLastFailedStreamConnectionTime (
@@ -682,7 +683,7 @@ export class RealtimeHandler {
682683 private async onVisibilityChange ( visible : unknown ) : Promise < void > {
683684 this . isInBackground = ! visible ;
684685 if ( ! visible ) {
685- await this . closeRealtimeHttpConnection ( ) ;
686+ await this . closeRealtimeHttpConnection ( ) ;
686687 } else if ( visible ) {
687688 await this . beginRealtime ( ) ;
688689 }
0 commit comments