Use app scoped CoroutineScope (#3403)
This commit is contained in:
@@ -15,6 +15,7 @@ import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import tachiyomi.core.common.util.lang.launchIO
|
||||
import tachiyomi.domain.source.model.StubSource
|
||||
import tachiyomi.domain.source.repository.StubSourceRepository
|
||||
import tachiyomi.domain.source.service.SourceManager
|
||||
@@ -26,6 +27,7 @@ import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
class AndroidSourceManager(
|
||||
private val context: Context,
|
||||
private val scope: CoroutineScope,
|
||||
private val extensionManager: ExtensionManager,
|
||||
private val sourceRepository: StubSourceRepository,
|
||||
) : SourceManager {
|
||||
@@ -35,8 +37,6 @@ class AndroidSourceManager(
|
||||
|
||||
private val downloadManager: DownloadManager by injectLazy()
|
||||
|
||||
private val scope = CoroutineScope(Job() + Dispatchers.IO)
|
||||
|
||||
private val sourcesMapFlow = MutableStateFlow(ConcurrentHashMap<Long, Source>())
|
||||
|
||||
private val stubSourcesMap = ConcurrentHashMap<Long, StubSource>()
|
||||
@@ -46,7 +46,7 @@ class AndroidSourceManager(
|
||||
}
|
||||
|
||||
init {
|
||||
scope.launch {
|
||||
scope.launchIO {
|
||||
extensionManager.installedExtensionsFlow
|
||||
.collectLatest { extensions ->
|
||||
val mutableMap = ConcurrentHashMap<Long, Source>(
|
||||
@@ -69,7 +69,7 @@ class AndroidSourceManager(
|
||||
}
|
||||
}
|
||||
|
||||
scope.launch {
|
||||
scope.launchIO {
|
||||
sourceRepository.subscribeAll()
|
||||
.collectLatest { sources ->
|
||||
val mutableMap = stubSourcesMap.toMutableMap()
|
||||
@@ -100,9 +100,9 @@ class AndroidSourceManager(
|
||||
}
|
||||
|
||||
private fun registerStubSource(source: StubSource) {
|
||||
scope.launch {
|
||||
scope.launchIO {
|
||||
val dbSource = sourceRepository.getStubSource(source.id)
|
||||
if (dbSource == source) return@launch
|
||||
if (dbSource == source) return@launchIO
|
||||
sourceRepository.upsertStubSource(source.id, source.lang, source.name)
|
||||
if (dbSource != null) {
|
||||
downloadManager.renameSource(dbSource, source)
|
||||
|
||||
Reference in New Issue
Block a user