Use coroutines for async loading of modules

This commit is contained in:
arkon 2020-02-02 17:06:51 -05:00 committed by Jay
parent 2be1256898
commit e9e9e10805

View File

@ -11,8 +11,8 @@ import eu.kanade.tachiyomi.data.track.TrackManager
import eu.kanade.tachiyomi.extension.ExtensionManager import eu.kanade.tachiyomi.extension.ExtensionManager
import eu.kanade.tachiyomi.network.NetworkHelper import eu.kanade.tachiyomi.network.NetworkHelper
import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.SourceManager
import rx.Observable import kotlinx.coroutines.GlobalScope
import rx.schedulers.Schedulers import kotlinx.coroutines.launch
import uy.kohesive.injekt.api.* import uy.kohesive.injekt.api.*
class AppModule(val app: Application) : InjektModule { class AppModule(val app: Application) : InjektModule {
@ -43,20 +43,16 @@ class AppModule(val app: Application) : InjektModule {
// Asynchronously init expensive components for a faster cold start // Asynchronously init expensive components for a faster cold start
rxAsync { get<PreferencesHelper>() } GlobalScope.launch { get<PreferencesHelper>() }
rxAsync { get<NetworkHelper>() } GlobalScope.launch { get<NetworkHelper>() }
rxAsync { get<SourceManager>() } GlobalScope.launch { get<SourceManager>() }
rxAsync { get<DatabaseHelper>() } GlobalScope.launch { get<DatabaseHelper>() }
rxAsync { get<DownloadManager>() } GlobalScope.launch { get<DownloadManager>() }
} }
private fun rxAsync(block: () -> Unit) {
Observable.fromCallable { block() }.subscribeOn(Schedulers.computation()).subscribe()
}
} }