From eefd09d0227c61a1f89b0b9d5dd00bef43112c49 Mon Sep 17 00:00:00 2001 From: ganfra Date: Wed, 3 Jul 2019 14:48:03 +0200 Subject: [PATCH] Dagger: don't create MatrixCoroutineDispatchers multiple time!! --- .../matrix/android/internal/di/MatrixModule.kt | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MatrixModule.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MatrixModule.kt index 875dd5f7..260c80f1 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MatrixModule.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MatrixModule.kt @@ -23,6 +23,7 @@ import android.os.HandlerThread import dagger.Module import dagger.Provides import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers +import im.vector.matrix.android.internal.util.createBackgroundHandler import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.android.asCoroutineDispatcher import org.matrix.olm.OlmManager @@ -32,15 +33,12 @@ internal object MatrixModule { @JvmStatic @Provides + @MatrixScope fun providesMatrixCoroutineDispatchers(): MatrixCoroutineDispatchers { - val THREAD_CRYPTO_NAME = "Crypto_Thread" - val handlerThread = HandlerThread(THREAD_CRYPTO_NAME) - handlerThread.start() - return MatrixCoroutineDispatchers(io = Dispatchers.IO, - computation = Dispatchers.IO, - main = Dispatchers.Main, - crypto = Handler(handlerThread.looper).asCoroutineDispatcher("crypto") + computation = Dispatchers.IO, + main = Dispatchers.Main, + crypto = createBackgroundHandler("Crypto_Thread").asCoroutineDispatcher() ) }