avoiding unneeded main context switch

This commit is contained in:
Adam Brown 2022-08-01 15:12:39 +01:00
parent 410a7b525f
commit 6b754f3e03
2 changed files with 2 additions and 8 deletions

View File

@ -27,11 +27,7 @@ import im.vector.app.features.crypto.keysrequest.KeyRequestHandler
import im.vector.app.features.crypto.verification.IncomingVerificationRequestHandler
import im.vector.app.features.notifications.PushRuleTriggerListener
import im.vector.app.features.session.SessionListener
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.newSingleThreadContext
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import org.matrix.android.sdk.api.auth.AuthenticationService
import org.matrix.android.sdk.api.session.Session
import timber.log.Timber
@ -106,9 +102,7 @@ class ActiveSessionHolder @Inject constructor(
suspend fun getOrInitializeSession(startSync: Boolean): Session? {
return activeSessionReference.get() ?: sessionInitializer.tryInitialize(readCurrentSession = { activeSessionReference.get() }) { session ->
setActiveSession(session)
withContext(Dispatchers.Main) {
session.configureAndStart(applicationContext, startSyncing = startSync)
}
session.configureAndStart(applicationContext, startSyncing = startSync)
}
}

View File

@ -37,7 +37,7 @@ class SessionInitializer @Inject constructor(
* @param initializer callback to allow additional initialization on the Session, such as setting the in-memory Session instance.
* @return the initialized Session or null when no authenticated sessions are available.
*/
suspend fun tryInitialize(readCurrentSession: () -> Session?, initializer: suspend (Session) -> Unit): Session? {
suspend fun tryInitialize(readCurrentSession: () -> Session?, initializer: (Session) -> Unit): Session? {
return withContext(INITIALIZER_CONTEXT) {
val currentInMemorySession = readCurrentSession()
when {