|
|
|
|
@ -14,8 +14,10 @@ import kotlinx.coroutines.flow.channelFlow
|
|
|
|
|
import kotlinx.coroutines.flow.combine
|
|
|
|
|
import kotlinx.coroutines.flow.filterNotNull
|
|
|
|
|
import kotlinx.coroutines.flow.flatMapLatest
|
|
|
|
|
import kotlinx.coroutines.flow.onEmpty
|
|
|
|
|
import kotlinx.coroutines.flow.runningFold
|
|
|
|
|
import kotlinx.coroutines.flow.stateIn
|
|
|
|
|
import kotlinx.coroutines.joinAll
|
|
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
|
import kotlinx.coroutines.plus
|
|
|
|
|
import kotlinx.coroutines.sync.Semaphore
|
|
|
|
|
@ -112,11 +114,11 @@ class MultiSearchViewModel @Inject constructor(
|
|
|
|
|
return@channelFlow
|
|
|
|
|
}
|
|
|
|
|
val semaphore = Semaphore(MAX_PARALLELISM)
|
|
|
|
|
for (source in sources) {
|
|
|
|
|
sources.mapNotNull { source ->
|
|
|
|
|
val repository = mangaRepositoryFactory.create(source)
|
|
|
|
|
if (!repository.isSearchSupported) {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
null
|
|
|
|
|
} else {
|
|
|
|
|
launch {
|
|
|
|
|
val item = runCatchingCancellable {
|
|
|
|
|
semaphore.withPermit {
|
|
|
|
|
@ -143,6 +145,8 @@ class MultiSearchViewModel @Inject constructor(
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}.joinAll()
|
|
|
|
|
}.runningFold<MultiSearchListModel, List<MultiSearchListModel>?>(null) { list, item -> list.orEmpty() + item }
|
|
|
|
|
.filterNotNull()
|
|
|
|
|
.onEmpty { emit(emptyList()) }
|
|
|
|
|
}
|
|
|
|
|
|