@@ -10,11 +10,11 @@ import {
1010 DBAdapterListener ,
1111 DBLockOptions ,
1212 LockContext ,
13- mutexRunExclusive ,
13+ Mutex ,
1414 QueryResult ,
15+ timeoutSignal ,
1516 Transaction
1617} from '@powersync/web' ;
17- import { Mutex } from 'async-mutex' ;
1818import { PowerSyncCore } from '../plugin/PowerSyncCore.js' ;
1919import { messageForErrorCode } from '../plugin/PowerSyncPlugin.js' ;
2020import { CapacitorSQLiteOpenFactoryOptions , DEFAULT_SQLITE_OPTIONS } from './CapacitorSQLiteOpenFactory.js' ;
@@ -228,39 +228,31 @@ class CapacitorConnectionPool extends BaseObserver<DBAdapterListener> implements
228228 }
229229
230230 readLock < T > ( fn : ( tx : LockContext ) => Promise < T > , options ?: DBLockOptions ) : Promise < T > {
231- return mutexRunExclusive (
232- this . readMutex ,
233- async ( ) => {
234- await this . initializedPromise ;
235- return await fn ( this . generateLockContext ( this . readConnection ) ) ;
236- } ,
237- options
238- ) ;
231+ return this . readMutex . runExclusive ( async ( ) => {
232+ await this . initializedPromise ;
233+ return fn ( this . generateLockContext ( this . readConnection ) ) ;
234+ } , timeoutSignal ( options ?. timeoutMs ) ) ;
239235 }
240236
241237 writeLock < T > ( fn : ( tx : LockContext ) => Promise < T > , options ?: DBLockOptions ) : Promise < T > {
242- return mutexRunExclusive (
243- this . writeMutex ,
244- async ( ) => {
245- await this . initializedPromise ;
246- const result = await fn ( this . generateLockContext ( this . writeConnection ) ) ;
247-
248- // Fetch table updates
249- const updates = await this . writeConnection . query ( "SELECT powersync_update_hooks('get') AS table_name" ) ;
250- const jsonUpdates = updates . values ?. [ 0 ] ;
251- if ( ! jsonUpdates || ! jsonUpdates . table_name ) {
252- throw new Error ( 'Could not fetch table updates' ) ;
253- }
254- const notification : BatchedUpdateNotification = {
255- rawUpdates : [ ] ,
256- tables : JSON . parse ( jsonUpdates . table_name ) ,
257- groupedUpdates : { }
258- } ;
259- this . iterateListeners ( ( l ) => l . tablesUpdated ?.( notification ) ) ;
260- return result ;
261- } ,
262- options
263- ) ;
238+ return this . writeMutex . runExclusive ( async ( ) => {
239+ await this . initializedPromise ;
240+ const result = await fn ( this . generateLockContext ( this . writeConnection ) ) ;
241+
242+ // Fetch table updates
243+ const updates = await this . writeConnection . query ( "SELECT powersync_update_hooks('get') AS table_name" ) ;
244+ const jsonUpdates = updates . values ?. [ 0 ] ;
245+ if ( ! jsonUpdates || ! jsonUpdates . table_name ) {
246+ throw new Error ( 'Could not fetch table updates' ) ;
247+ }
248+ const notification : BatchedUpdateNotification = {
249+ rawUpdates : [ ] ,
250+ tables : JSON . parse ( jsonUpdates . table_name ) ,
251+ groupedUpdates : { }
252+ } ;
253+ this . iterateListeners ( ( l ) => l . tablesUpdated ?.( notification ) ) ;
254+ return result ;
255+ } , timeoutSignal ( options ?. timeoutMs ) ) ;
264256 }
265257
266258 refreshSchema ( ) : Promise < void > {
0 commit comments