Use coroutines for async loading of modules
This commit is contained in:
parent
2be1256898
commit
e9e9e10805
1 changed files with 7 additions and 11 deletions
|
@ -11,8 +11,8 @@ import eu.kanade.tachiyomi.data.track.TrackManager
|
|||
import eu.kanade.tachiyomi.extension.ExtensionManager
|
||||
import eu.kanade.tachiyomi.network.NetworkHelper
|
||||
import eu.kanade.tachiyomi.source.SourceManager
|
||||
import rx.Observable
|
||||
import rx.schedulers.Schedulers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import uy.kohesive.injekt.api.*
|
||||
|
||||
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
|
||||
|
||||
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()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Reference in a new issue