Skip to content

Commit 19836c8

Browse files
Fix
1 parent a9d8b57 commit 19836c8

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

packages/firestore/src/core/firestore_client.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,19 @@ export class FirestoreClient {
137137
);
138138
}
139139

140+
/**
141+
* Checks that the client has not been terminated. Ensures that other methods on
142+
* this class cannot be called after the client is terminated.
143+
*/
144+
verifyNotTerminated(): void {
145+
if (this.asyncQueue.isShuttingDown) {
146+
throw new FirestoreError(
147+
Code.FAILED_PRECONDITION,
148+
'The client has already been terminated.'
149+
);
150+
}
151+
}
152+
140153
terminate(): Promise<void> {
141154
this.asyncQueue.enterRestrictedMode();
142155
const deferred = new Deferred();
@@ -169,6 +182,8 @@ export class FirestoreClient {
169182
async function ensureOfflineComponents(
170183
firestoreClient: FirestoreClient
171184
): Promise<OfflineComponentProvider> {
185+
firestoreClient.verifyNotTerminated();
186+
172187
if (!firestoreClient.offlineComponents) {
173188
logDebug(LOG_TAG, 'Using default OfflineComponentProvider');
174189
await setOfflineComponentProvider(
@@ -183,6 +198,8 @@ async function ensureOfflineComponents(
183198
async function ensureOnlineComponents(
184199
firestoreClient: FirestoreClient
185200
): Promise<OnlineComponentProvider> {
201+
firestoreClient.verifyNotTerminated();
202+
186203
if (!firestoreClient.onlineComponents) {
187204
logDebug(LOG_TAG, 'Using default OnlineComponentProvider');
188205
await setOnlineComponentProvider(

packages/firestore/src/util/async_queue.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,12 +303,6 @@ export class AsyncQueue {
303303
* when the promise returned by the new operation is (with its value).
304304
*/
305305
enqueue<T extends unknown>(op: () => Promise<T>): Promise<T> {
306-
if (this.isShuttingDown) {
307-
throw new FirestoreError(
308-
Code.FAILED_PRECONDITION,
309-
'The client has already been terminated.'
310-
);
311-
}
312306
this.verifyNotFailed();
313307
if (this._isShuttingDown) {
314308
// Return a Promise which never resolves.

0 commit comments

Comments
 (0)