mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 08:42:00 +01:00
Avoid concurrency crashes in SourceManager
This commit is contained in:
parent
ad107860b9
commit
d0c4463ab3
@ -21,6 +21,7 @@ import kotlinx.coroutines.launch
|
|||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
|
|
||||||
class SourceManager(
|
class SourceManager(
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
@ -31,7 +32,7 @@ class SourceManager(
|
|||||||
|
|
||||||
private val scope = CoroutineScope(Job() + Dispatchers.IO)
|
private val scope = CoroutineScope(Job() + Dispatchers.IO)
|
||||||
|
|
||||||
private var sourcesMap = emptyMap<Long, Source>()
|
private var sourcesMap = ConcurrentHashMap<Long, Source>()
|
||||||
set(value) {
|
set(value) {
|
||||||
field = value
|
field = value
|
||||||
sourcesMapFlow.value = field
|
sourcesMapFlow.value = field
|
||||||
@ -39,7 +40,7 @@ class SourceManager(
|
|||||||
|
|
||||||
private val sourcesMapFlow = MutableStateFlow(sourcesMap)
|
private val sourcesMapFlow = MutableStateFlow(sourcesMap)
|
||||||
|
|
||||||
private val stubSourcesMap = mutableMapOf<Long, StubSource>()
|
private val stubSourcesMap = ConcurrentHashMap<Long, StubSource>()
|
||||||
|
|
||||||
val catalogueSources: Flow<List<CatalogueSource>> = sourcesMapFlow.map { it.values.filterIsInstance<CatalogueSource>() }
|
val catalogueSources: Flow<List<CatalogueSource>> = sourcesMapFlow.map { it.values.filterIsInstance<CatalogueSource>() }
|
||||||
val onlineSources: Flow<List<HttpSource>> = catalogueSources.map { sources -> sources.filterIsInstance<HttpSource>() }
|
val onlineSources: Flow<List<HttpSource>> = catalogueSources.map { sources -> sources.filterIsInstance<HttpSource>() }
|
||||||
@ -48,7 +49,7 @@ class SourceManager(
|
|||||||
scope.launch {
|
scope.launch {
|
||||||
extensionManager.installedExtensionsFlow
|
extensionManager.installedExtensionsFlow
|
||||||
.collectLatest { extensions ->
|
.collectLatest { extensions ->
|
||||||
val mutableMap = mutableMapOf<Long, Source>(LocalSource.ID to LocalSource(context))
|
val mutableMap = ConcurrentHashMap<Long, Source>(mapOf(LocalSource.ID to LocalSource(context)))
|
||||||
extensions.forEach { extension ->
|
extensions.forEach { extension ->
|
||||||
extension.sources.forEach {
|
extension.sources.forEach {
|
||||||
mutableMap[it.id] = it
|
mutableMap[it.id] = it
|
||||||
|
Loading…
Reference in New Issue
Block a user