Skip to content

Commit ef6b1ec

Browse files
committed
Reverted OPFS example change. Using abort controller signal to release lock.
1 parent 619f193 commit ef6b1ec

File tree

3 files changed

+8
-23
lines changed

3 files changed

+8
-23
lines changed

.changeset/blue-pets-count.md

Lines changed: 0 additions & 12 deletions
This file was deleted.

demos/react-supabase-todolist/src/components/providers/SystemProvider.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { AppSchema } from '@/library/powersync/AppSchema';
33
import { SupabaseConnector } from '@/library/powersync/SupabaseConnector';
44
import { CircularProgress } from '@mui/material';
55
import { PowerSyncContext } from '@powersync/react';
6-
import { PowerSyncDatabase, WASQLiteOpenFactory, WASQLiteVFS } from '@powersync/web';
6+
import { PowerSyncDatabase } from '@powersync/web';
77
import Logger from 'js-logger';
88
import React, { Suspense } from 'react';
99
import { NavigationPanelContextProvider } from '../navigation/NavigationPanelContext';
@@ -13,10 +13,9 @@ export const useSupabase = () => React.useContext(SupabaseContext);
1313

1414
export const db = new PowerSyncDatabase({
1515
schema: AppSchema,
16-
database: new WASQLiteOpenFactory({
17-
dbFilename: 'one.sqlite',
18-
vfs: WASQLiteVFS.OPFSCoopSyncVFS
19-
})
16+
database: {
17+
dbFilename: 'example.db'
18+
}
2019
});
2120

2221
export const SystemProvider = ({ children }: { children: React.ReactNode }) => {
@@ -32,7 +31,7 @@ export const SystemProvider = ({ children }: { children: React.ReactNode }) => {
3231

3332
powerSync.init();
3433
const l = connector.registerListener({
35-
initialized: () => {},
34+
initialized: () => { },
3635
sessionStarted: () => {
3736
powerSync.connect(connector);
3837
}

packages/web/src/db/adapters/WorkerWrappedAsyncDatabaseConnection.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,9 @@ export type WrappedWorkerConnectionOptions<Config extends ResolvedWebSQLOpenOpti
2929
export class WorkerWrappedAsyncDatabaseConnection<Config extends ResolvedWebSQLOpenOptions = ResolvedWebSQLOpenOptions>
3030
implements AsyncDatabaseConnection
3131
{
32-
protected releaseSharedConnectionLock: (() => void) | null;
3332
protected lockAbortController: AbortController;
3433

3534
constructor(protected options: WrappedWorkerConnectionOptions<Config>) {
36-
this.releaseSharedConnectionLock = null;
3735
this.lockAbortController = new AbortController();
3836
}
3937

@@ -74,8 +72,9 @@ export class WorkerWrappedAsyncDatabaseConnection<Config extends ResolvedWebSQLO
7472

7573
// Hold the lock while the shared connection is in use.
7674
await new Promise<void>((releaseLock) => {
77-
// We can use the resolver to free the lock
78-
this.releaseSharedConnectionLock = releaseLock;
75+
this.lockAbortController.signal.addEventListener('abort', () => {
76+
releaseLock();
77+
});
7978
});
8079
}
8180
)
@@ -98,7 +97,6 @@ export class WorkerWrappedAsyncDatabaseConnection<Config extends ResolvedWebSQLO
9897
async close(): Promise<void> {
9998
// Abort any pending lock requests.
10099
this.lockAbortController.abort();
101-
this.releaseSharedConnectionLock?.();
102100
await this.baseConnection.close();
103101
this.options.remote[Comlink.releaseProxy]();
104102
this.options.onClose?.();

0 commit comments

Comments
 (0)