From 58639ea70f16bcfa0b4c0c8db33bf3817a2d0ae7 Mon Sep 17 00:00:00 2001 From: Oussama Hassine Date: Thu, 21 Sep 2023 12:05:00 +0200 Subject: [PATCH] chore: run some operations on worker thread (#2075) --- .../logic/feature/ProteusClientProvider.kt | 16 +++++++++------- .../feature/call/usecase/AnswerCallUseCase.kt | 12 +++++++----- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/ProteusClientProvider.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/ProteusClientProvider.kt index a597696c2a2..c4582442f27 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/ProteusClientProvider.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/ProteusClientProvider.kt @@ -80,15 +80,17 @@ class ProteusClientProviderImpl( override suspend fun getOrError(): Either { return mutex.withLock { - _proteusClient?.let { Either.Right(it) } ?: run { - if (FileUtil.isDirectoryNonEmpty(rootProteusPath)) { - wrapProteusRequest { - createProteusClient().also { - _proteusClient = it + withContext(dispatcher.io) { + _proteusClient?.let { Either.Right(it) } ?: run { + if (FileUtil.isDirectoryNonEmpty(rootProteusPath)) { + wrapProteusRequest { + createProteusClient().also { + _proteusClient = it + } } + } else { + Either.Left(CoreFailure.MissingClientRegistration) } - } else { - Either.Left(CoreFailure.MissingClientRegistration) } } } diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/call/usecase/AnswerCallUseCase.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/call/usecase/AnswerCallUseCase.kt index c1fa58cb5bc..578704ae52d 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/call/usecase/AnswerCallUseCase.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/call/usecase/AnswerCallUseCase.kt @@ -27,6 +27,7 @@ import com.wire.kalium.util.KaliumDispatcherImpl import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.map +import kotlinx.coroutines.withContext /** * This use case is responsible for answering a call. @@ -66,10 +67,11 @@ internal class AnswerCallUseCaseImpl( unMuteCall(conversationId) } } - - callManager.value.answerCall( - conversationId = conversationId, - isAudioCbr = kaliumConfigs.forceConstantBitrateCalls - ) + withContext(dispatchers.default) { + callManager.value.answerCall( + conversationId = conversationId, + isAudioCbr = kaliumConfigs.forceConstantBitrateCalls + ) + } } }