Dagger: don't create MatrixCoroutineDispatchers multiple time!!

This commit is contained in:
ganfra 2019-07-03 14:48:03 +02:00
parent ef597cc67a
commit eefd09d022
1 changed files with 5 additions and 7 deletions

View File

@ -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()
)
}