@@ -294,41 +294,40 @@ export class IndexedDbPersistence implements Persistence {
294294 debugAssert ( ! this . started , 'IndexedDbPersistence double-started!' ) ;
295295 debugAssert ( this . window !== null , "Expected 'window' to be defined" ) ;
296296
297- try {
298- await this . simpleDb . ensureDb ( ) ;
299-
300- // NOTE: This is expected to fail sometimes (in the case of another tab already
301- // having the persistence lock), so it's the first thing we should do.
302- await this . updateClientMetadataAndTryBecomePrimary ( ) ;
303-
304- if ( ! this . isPrimary && ! this . allowTabSynchronization ) {
305- // Fail `start()` if `synchronizeTabs` is disabled and we cannot
306- // obtain the primary lease.
307- throw new FirestoreError (
308- Code . FAILED_PRECONDITION ,
309- PRIMARY_LEASE_EXCLUSIVE_ERROR_MSG
310- ) ;
311- }
312- this . attachVisibilityHandler ( ) ;
313- this . attachWindowUnloadHook ( ) ;
314-
315- this . scheduleClientMetadataAndPrimaryLeaseRefreshes ( ) ;
316-
317- const highestListenSequenceNumber = await this . runTransaction (
318- 'getHighestListenSequenceNumber' ,
319- 'readonly' ,
320- txn => this . targetCache . getHighestSequenceNumber ( txn )
321- ) ;
297+ return this . updateClientMetadataAndTryBecomePrimary ( )
298+ . then ( ( ) => {
299+ if ( ! this . isPrimary && ! this . allowTabSynchronization ) {
300+ // Fail `start()` if `synchronizeTabs` is disabled and we cannot
301+ // obtain the primary lease.
302+ throw new FirestoreError (
303+ Code . FAILED_PRECONDITION ,
304+ PRIMARY_LEASE_EXCLUSIVE_ERROR_MSG
305+ ) ;
306+ }
307+ this . attachVisibilityHandler ( ) ;
308+ this . attachWindowUnloadHook ( ) ;
322309
323- this . listenSequence = new ListenSequence (
324- highestListenSequenceNumber ,
325- this . sequenceNumberSyncer
326- ) ;
310+ this . scheduleClientMetadataAndPrimaryLeaseRefreshes ( ) ;
327311
328- this . _started = true ;
329- } finally {
330- this . simpleDb . close ( ) ;
331- }
312+ return this . runTransaction (
313+ 'getHighestListenSequenceNumber' ,
314+ 'readonly' ,
315+ txn => this . targetCache . getHighestSequenceNumber ( txn )
316+ ) ;
317+ } )
318+ . then ( highestListenSequenceNumber => {
319+ this . listenSequence = new ListenSequence (
320+ highestListenSequenceNumber ,
321+ this . sequenceNumberSyncer
322+ ) ;
323+ } )
324+ . then ( ( ) => {
325+ this . _started = true ;
326+ } )
327+ . catch ( reason => {
328+ this . simpleDb && this . simpleDb . close ( ) ;
329+ return Promise . reject ( reason ) ;
330+ } ) ;
332331 }
333332
334333 /**
0 commit comments