@@ -22,6 +22,7 @@ import kotlinx.coroutines.flow.channelFlow
22
22
import kotlinx.coroutines.flow.filter
23
23
import kotlinx.coroutines.flow.onSubscription
24
24
import kotlinx.coroutines.flow.transform
25
+ import kotlinx.coroutines.launch
25
26
import kotlinx.coroutines.sync.Mutex
26
27
import kotlinx.coroutines.withContext
27
28
import kotlin.time.Duration.Companion.milliseconds
@@ -212,9 +213,24 @@ internal class InternalDatabaseImpl(
212
213
readPool.obtainConnection()
213
214
} else {
214
215
writeLockMutex.lock()
215
- RawConnectionLease (writeConnection, writeLockMutex::unlock)
216
+ RawConnectionLease (writeConnection) {
217
+ scope.launch {
218
+ // When we've leased a write connection, we may have to update table update
219
+ // flows after users ran their custom statements.
220
+ // For internal queries, this happens with leaseWrite() and an asynchronous call
221
+ // in internalWriteLock
222
+ updates.fireTableUpdates()
223
+ }
224
+
225
+ writeLockMutex.unlock()
226
+ }
216
227
}
217
228
229
+ private suspend fun leaseWrite (): SQLiteConnection {
230
+ writeLockMutex.lock()
231
+ return RawConnectionLease (writeConnection, writeLockMutex::unlock)
232
+ }
233
+
218
234
/* *
219
235
* Creates a read lock while providing an internal transactor for transactions
220
236
*/
@@ -251,7 +267,7 @@ internal class InternalDatabaseImpl(
251
267
@OptIn(ExperimentalPowerSyncAPI ::class )
252
268
private suspend fun <R > internalWriteLock (callback : (SQLiteConnection ) -> R ): R =
253
269
withContext(dbContext) {
254
- val lease = leaseConnection(readOnly = false )
270
+ val lease = leaseWrite( )
255
271
try {
256
272
runWrapped {
257
273
catchSwiftExceptions {
0 commit comments