Skip to content

Commit

Permalink
Run SyncService.start and stop with a non-UI dispatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
jmartinesp committed Jan 10, 2025
1 parent 63dbf93 commit dccb73c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ class RustMatrixClient(

private val innerRoomListService = innerSyncService.roomListService()

private val rustSyncService = RustSyncService(innerSyncService, sessionCoroutineScope)
private val rustSyncService = RustSyncService(
innerSyncService = innerSyncService,
sessionCoroutineScope = sessionCoroutineScope,
syncServiceDispatcher = sessionDispatcher
)
private val pushersService = RustPushersService(
client = innerClient,
dispatchers = dispatchers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package io.element.android.libraries.matrix.impl.sync

import io.element.android.libraries.matrix.api.sync.SyncService
import io.element.android.libraries.matrix.api.sync.SyncState
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.flow.SharingStarted
Expand All @@ -25,7 +26,8 @@ import org.matrix.rustcomponents.sdk.SyncService as InnerSyncService

class RustSyncService(
private val innerSyncService: InnerSyncService,
sessionCoroutineScope: CoroutineScope
sessionCoroutineScope: CoroutineScope,
private val syncServiceDispatcher: CoroutineDispatcher,
) : SyncService {
private val isServiceReady = AtomicBoolean(true)

Expand All @@ -35,7 +37,9 @@ class RustSyncService(
return@runCatching
}
Timber.i("Start sync")
innerSyncService.start()
withContext(syncServiceDispatcher) {
innerSyncService.start()
}
}.onFailure {
Timber.d("Start sync failed: $it")
}
Expand All @@ -46,7 +50,9 @@ class RustSyncService(
return@runCatching
}
Timber.i("Stop sync")
innerSyncService.stop()
withContext(syncServiceDispatcher) {
innerSyncService.stop()
}
}.onFailure {
Timber.d("Stop sync failed: $it")
}
Expand Down

0 comments on commit dccb73c

Please sign in to comment.