Skip to content

Commit c0ab7b4

Browse files
author
Brian Chen
authored
Standardize shutdown checking logic (#1776)
1 parent 0c0000a commit c0ab7b4

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

packages/firestore/src/core/firestore_client.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -495,23 +495,22 @@ export class FirestoreClient {
495495
}
496496

497497
shutdown(): Promise<void> {
498-
if (this.isShutdown === true) {
499-
return Promise.resolve();
500-
}
501498
return this.asyncQueue.enqueue(async () => {
502-
// PORTING NOTE: LocalStore does not need an explicit shutdown on web.
503-
if (this.lruScheduler) {
504-
this.lruScheduler.stop();
499+
if (!this.isShutdown) {
500+
// PORTING NOTE: LocalStore does not need an explicit shutdown on web.
501+
if (this.lruScheduler) {
502+
this.lruScheduler.stop();
503+
}
504+
await this.remoteStore.shutdown();
505+
await this.sharedClientState.shutdown();
506+
await this.persistence.shutdown();
507+
508+
// `removeChangeListener` must be called after shutting down the
509+
// RemoteStore as it will prevent the RemoteStore from retrieving
510+
// auth tokens.
511+
this.credentials.removeChangeListener();
512+
this.isShutdown = true;
505513
}
506-
await this.remoteStore.shutdown();
507-
await this.sharedClientState.shutdown();
508-
await this.persistence.shutdown();
509-
510-
// `removeChangeListener` must be called after shutting down the
511-
// RemoteStore as it will prevent the RemoteStore from retrieving
512-
// auth tokens.
513-
this.credentials.removeChangeListener();
514-
this.isShutdown = true;
515514
});
516515
}
517516

0 commit comments

Comments
 (0)