@@ -190,7 +190,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
190190 */
191191 protected syncStreamInitPromise : Promise < void > | null ;
192192 /**
193- * Active disconnect operation. Call disconnect multiple times
193+ * Active disconnect operation. Calling disconnect multiple times
194194 * will resolve to the same operation.
195195 */
196196 protected disconnectingPromise : Promise < void > | null ;
@@ -457,7 +457,8 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
457457 }
458458
459459 /**
460- * Locking mechagnism for exclusively running critical portions of connect/disconnect operations.
460+ * Locking mechanism for exclusively running critical portions of connect/disconnect operations.
461+ * Locking here is mostly only important on web for multiple tab scenarios.
461462 */
462463 protected abstract runExclusive < T > ( callback : ( ) => Promise < T > ) : Promise < T > ;
463464
@@ -573,6 +574,13 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
573574 *
574575 * Use {@link connect} to connect again.
575576 */
577+ async disconnect ( ) {
578+ await this . waitForReady ( ) ;
579+ // This will help abort pending connects
580+ this . pendingConnectionOptions = null ;
581+ await this . disconnectInternal ( ) ;
582+ }
583+
576584 protected async disconnectInternal ( ) {
577585 if ( this . disconnectingPromise ) {
578586 // A disconnect is already in progress
@@ -583,27 +591,17 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
583591 // (syncStreamImplementation must be assigned before we can properly dispose it)
584592 await this . syncStreamInitPromise ;
585593
586- this . disconnectingPromise = ( async ( ) => {
587- await this . syncStreamImplementation ?. disconnect ( ) ;
588- this . syncStatusListenerDisposer ?.( ) ;
589- await this . syncStreamImplementation ?. dispose ( ) ;
590- this . syncStreamImplementation = undefined ;
591- } ) ( ) ;
594+ this . disconnectingPromise = this . performDisconnect ( ) ;
592595
593596 await this . disconnectingPromise ;
594597 this . disconnectingPromise = null ;
595598 }
596599
597- /**
598- * Close the sync connection.
599- *
600- * Use {@link connect} to connect again.
601- */
602- async disconnect ( ) {
603- await this . waitForReady ( ) ;
604- // This will help abort pending connects
605- this . pendingConnectionOptions = null ;
606- await this . disconnectInternal ( ) ;
600+ protected async performDisconnect ( ) {
601+ await this . syncStreamImplementation ?. disconnect ( ) ;
602+ this . syncStatusListenerDisposer ?.( ) ;
603+ await this . syncStreamImplementation ?. dispose ( ) ;
604+ this . syncStreamImplementation = undefined ;
607605 }
608606
609607 /**
0 commit comments