Skip to content

Commit f882ad4

Browse files
committed
close connection async
1 parent 024e042 commit f882ad4

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

packages/remote-config/src/client/realtime_handler.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

packages/remote-config/test/remote_config.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -430,9 +430,9 @@ describe('RemoteConfig', () => {
430430
expect(activateResponse).to.be.false;
431431
expect(storage.setActiveConfigEtag).to.not.have.been.called;
432432
expect(storageCache.setActiveConfig).to.not.have.been.called;
433-
expect(storage.setActiveConfigTemplateVersion).to.not.have.been.calledWith(
434-
TEMPLATE_VERSION
435-
);
433+
expect(
434+
storage.setActiveConfigTemplateVersion
435+
).to.not.have.been.calledWith(TEMPLATE_VERSION);
436436
});
437437

438438
it('does not activate if fetched and active etags are the same', async () => {
@@ -450,9 +450,9 @@ describe('RemoteConfig', () => {
450450
expect(activateResponse).to.be.false;
451451
expect(storage.setActiveConfigEtag).to.not.have.been.called;
452452
expect(storageCache.setActiveConfig).to.not.have.been.called;
453-
expect(storage.setActiveConfigTemplateVersion).to.not.have.been.calledWith(
454-
TEMPLATE_VERSION
455-
);
453+
expect(
454+
storage.setActiveConfigTemplateVersion
455+
).to.not.have.been.calledWith(TEMPLATE_VERSION);
456456
});
457457

458458
it('activates if fetched and active etags are different', async () => {

0 commit comments

Comments
 (0)