@@ -309,16 +309,13 @@ export class Firestore implements firestore.FirebaseFirestore, FirebaseService {
309
309
// are already set to synchronize on the async queue.
310
310
private _firestoreClient : FirestoreClient | undefined ;
311
311
312
- private clientRunning : boolean ;
313
-
314
312
// Public for use in tests.
315
313
// TODO(mikelehen): Use modularized initialization instead.
316
314
readonly _queue = new AsyncQueue ( ) ;
317
315
318
316
_dataConverter : UserDataConverter ;
319
317
320
318
constructor ( databaseIdOrApp : FirestoreDatabase | FirebaseApp ) {
321
- this . clientRunning = false ;
322
319
const config = new FirestoreConfig ( ) ;
323
320
if ( typeof ( databaseIdOrApp as FirebaseApp ) . options === 'object' ) {
324
321
// This is very likely a Firebase app object
@@ -428,18 +425,21 @@ export class Firestore implements firestore.FirebaseFirestore, FirebaseService {
428
425
}
429
426
430
427
_clearPersistence ( ) : Promise < void > {
431
- if ( this . clientRunning ) {
432
- throw new FirestoreError (
433
- Code . FAILED_PRECONDITION ,
434
- 'Persistence cannot be cleared while the client is running'
435
- ) ;
436
- }
437
428
const persistenceKey = IndexedDbPersistence . buildStoragePrefix (
438
429
this . makeDatabaseInfo ( )
439
430
) ;
440
431
const deferred = new Deferred < void > ( ) ;
441
432
this . _queue . enqueueAndForget ( async ( ) => {
442
433
try {
434
+ if (
435
+ this . _firestoreClient !== undefined &&
436
+ ! this . _firestoreClient . clientShutdown
437
+ ) {
438
+ throw new FirestoreError (
439
+ Code . FAILED_PRECONDITION ,
440
+ 'Persistence cannot be cleared while this firestore instance is running.'
441
+ ) ;
442
+ }
443
443
await IndexedDbPersistence . clearPersistence ( persistenceKey ) ;
444
444
deferred . resolve ( ) ;
445
445
} catch ( e ) {
@@ -478,7 +478,6 @@ export class Firestore implements firestore.FirebaseFirestore, FirebaseService {
478
478
479
479
assert ( ! this . _firestoreClient , 'configureClient() called multiple times' ) ;
480
480
481
- this . clientRunning = true ;
482
481
const databaseInfo = this . makeDatabaseInfo ( ) ;
483
482
484
483
const preConverter = ( value : unknown ) => {
@@ -546,7 +545,6 @@ export class Firestore implements firestore.FirebaseFirestore, FirebaseService {
546
545
// throws an exception.
547
546
this . ensureClientConfigured ( ) ;
548
547
await this . _firestoreClient ! . shutdown ( ) ;
549
- this . clientRunning = false ;
550
548
}
551
549
} ;
552
550
0 commit comments