Skip to content

Commit be6b2b4

Browse files
cleanup
1 parent 1d155d9 commit be6b2b4

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

packages/common/rollup.config.mjs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import commonjs from '@rollup/plugin-commonjs';
22
import inject from '@rollup/plugin-inject';
33
import json from '@rollup/plugin-json';
44
import nodeResolve from '@rollup/plugin-node-resolve';
5+
import terser from '@rollup/plugin-terser';
56

67
export default (commandLineArgs) => {
78
const sourcemap = (commandLineArgs.sourceMap || 'true') == 'true';
@@ -25,8 +26,8 @@ export default (commandLineArgs) => {
2526
ReadableStream: ['web-streams-polyfill/ponyfill', 'ReadableStream'],
2627
// Used by can-ndjson-stream
2728
TextDecoder: ['text-encoding', 'TextDecoder']
28-
})
29-
// terser()
29+
}),
30+
terser()
3031
],
3132
// This makes life easier
3233
external: [

packages/common/src/client/AbstractPowerSyncDatabase.ts

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)