Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run SyncService.start() and stop() with a non-UI dispatcher #4133

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading