Skip to content

Commit 631db90

Browse files
committed
Use structured concurrency for sync jobs
1 parent 4ec18ba commit 631db90

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

core/src/commonMain/kotlin/com/powersync/db/PowerSyncDatabaseImpl.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ import com.powersync.utils.JsonParam
2424
import com.powersync.utils.JsonUtil
2525
import com.powersync.utils.throttle
2626
import com.powersync.utils.toJsonObject
27+
import kotlinx.coroutines.CancellationException
2728
import kotlinx.coroutines.CoroutineScope
2829
import kotlinx.coroutines.FlowPreview
2930
import kotlinx.coroutines.Job
3031
import kotlinx.coroutines.SupervisorJob
31-
import kotlinx.coroutines.cancelAndJoin
3232
import kotlinx.coroutines.ensureActive
3333
import kotlinx.coroutines.flow.Flow
3434
import kotlinx.coroutines.flow.filter
@@ -164,7 +164,7 @@ internal class PowerSyncDatabaseImpl(
164164
this.syncStream = stream
165165

166166
val db = this
167-
val job = SupervisorJob()
167+
val job = SupervisorJob(scope.coroutineContext[Job])
168168
syncSupervisorJob = job
169169
scope.launch(job) {
170170
launch {
@@ -367,7 +367,8 @@ internal class PowerSyncDatabaseImpl(
367367
private suspend fun disconnectInternal() {
368368
val syncJob = syncSupervisorJob
369369
if (syncJob != null && syncJob.isActive) {
370-
syncJob.cancelAndJoin()
370+
syncJob.cancel(CancellationException("disconnect() called"))
371+
syncJob.join()
371372
syncSupervisorJob = null
372373
}
373374

0 commit comments

Comments
 (0)