|
|
|
@ -89,11 +89,10 @@ class MultiSearchViewModel(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private suspend fun searchImpl(q: String) {
|
|
|
|
private suspend fun searchImpl(q: String) = coroutineScope {
|
|
|
|
val sources = settings.getMangaSources(includeHidden = false)
|
|
|
|
val sources = settings.getMangaSources(includeHidden = false)
|
|
|
|
val dispatcher = Dispatchers.Default.limitedParallelism(MAX_PARALLELISM)
|
|
|
|
val dispatcher = Dispatchers.Default.limitedParallelism(MAX_PARALLELISM)
|
|
|
|
val deferredList = coroutineScope {
|
|
|
|
val deferredList = sources.map { source ->
|
|
|
|
sources.map { source ->
|
|
|
|
|
|
|
|
async(dispatcher) {
|
|
|
|
async(dispatcher) {
|
|
|
|
runCatching {
|
|
|
|
runCatching {
|
|
|
|
val list = MangaRepository(source).getList(offset = 0, query = q)
|
|
|
|
val list = MangaRepository(source).getList(offset = 0, query = q)
|
|
|
|
@ -108,7 +107,7 @@ class MultiSearchViewModel(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
val errors = ArrayList<Throwable>()
|
|
|
|
val errors = ArrayList<Throwable>()
|
|
|
|
for (deferred in deferredList) {
|
|
|
|
for (deferred in deferredList) {
|
|
|
|
deferred.await()
|
|
|
|
deferred.await()
|
|
|
|
@ -120,9 +119,7 @@ class MultiSearchViewModel(
|
|
|
|
errors.add(it)
|
|
|
|
errors.add(it)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (listData.value.isNotEmpty()) {
|
|
|
|
if (listData.value.isEmpty()) {
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
when (errors.size) {
|
|
|
|
when (errors.size) {
|
|
|
|
0 -> Unit
|
|
|
|
0 -> Unit
|
|
|
|
1 -> throw errors[0]
|
|
|
|
1 -> throw errors[0]
|
|
|
|
@ -130,3 +127,4 @@ class MultiSearchViewModel(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|