@powersync/web 1.14.2 → 1.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.umd.js +36 -0
- package/dist/index.umd.js.map +1 -1
- package/dist/worker/SharedSyncImplementation.umd.js +36 -0
- package/dist/worker/SharedSyncImplementation.umd.js.map +1 -1
- package/lib/package.json +2 -2
- package/lib/src/db/adapters/WorkerWrappedAsyncDatabaseConnection.d.ts +1 -0
- package/lib/src/db/adapters/WorkerWrappedAsyncDatabaseConnection.js +36 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
package/dist/index.umd.js
CHANGED
|
@@ -34086,8 +34086,10 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
34086
34086
|
*/
|
|
34087
34087
|
class WorkerWrappedAsyncDatabaseConnection {
|
|
34088
34088
|
options;
|
|
34089
|
+
lockAbortController;
|
|
34089
34090
|
constructor(options) {
|
|
34090
34091
|
this.options = options;
|
|
34092
|
+
this.lockAbortController = new AbortController();
|
|
34091
34093
|
}
|
|
34092
34094
|
get baseConnection() {
|
|
34093
34095
|
return this.options.baseConnection;
|
|
@@ -34100,6 +34102,38 @@ class WorkerWrappedAsyncDatabaseConnection {
|
|
|
34100
34102
|
*/
|
|
34101
34103
|
async shareConnection() {
|
|
34102
34104
|
const { identifier, remote } = this.options;
|
|
34105
|
+
/**
|
|
34106
|
+
* Hold a navigator lock in order to avoid features such as Chrome's frozen tabs,
|
|
34107
|
+
* or Edge's sleeping tabs from pausing the thread for this connection.
|
|
34108
|
+
* This promise resolves once a lock is obtained.
|
|
34109
|
+
* This lock will be held as long as this connection is open.
|
|
34110
|
+
* The `shareConnection` method should not be called on multiple tabs concurrently.
|
|
34111
|
+
*/
|
|
34112
|
+
await new Promise((resolve, reject) => navigator.locks
|
|
34113
|
+
.request(`shared-connection-${this.options.identifier}`, {
|
|
34114
|
+
signal: this.lockAbortController.signal
|
|
34115
|
+
}, async () => {
|
|
34116
|
+
resolve();
|
|
34117
|
+
// Free the lock when the connection is already closed.
|
|
34118
|
+
if (this.lockAbortController.signal.aborted) {
|
|
34119
|
+
return;
|
|
34120
|
+
}
|
|
34121
|
+
// Hold the lock while the shared connection is in use.
|
|
34122
|
+
await new Promise((releaseLock) => {
|
|
34123
|
+
this.lockAbortController.signal.addEventListener('abort', () => {
|
|
34124
|
+
releaseLock();
|
|
34125
|
+
});
|
|
34126
|
+
});
|
|
34127
|
+
})
|
|
34128
|
+
// We aren't concerned with abort errors here
|
|
34129
|
+
.catch((ex) => {
|
|
34130
|
+
if (ex.name == 'AbortError') {
|
|
34131
|
+
resolve();
|
|
34132
|
+
}
|
|
34133
|
+
else {
|
|
34134
|
+
reject(ex);
|
|
34135
|
+
}
|
|
34136
|
+
}));
|
|
34103
34137
|
const newPort = await remote[comlink__WEBPACK_IMPORTED_MODULE_0__.createEndpoint]();
|
|
34104
34138
|
return { port: newPort, identifier };
|
|
34105
34139
|
}
|
|
@@ -34111,6 +34145,8 @@ class WorkerWrappedAsyncDatabaseConnection {
|
|
|
34111
34145
|
return this.baseConnection.registerOnTableChange(comlink__WEBPACK_IMPORTED_MODULE_0__.proxy(callback));
|
|
34112
34146
|
}
|
|
34113
34147
|
async close() {
|
|
34148
|
+
// Abort any pending lock requests.
|
|
34149
|
+
this.lockAbortController.abort();
|
|
34114
34150
|
await this.baseConnection.close();
|
|
34115
34151
|
this.options.remote[comlink__WEBPACK_IMPORTED_MODULE_0__.releaseProxy]();
|
|
34116
34152
|
this.options.onClose?.();
|