This commit is contained in:
Horis
2023-11-20 20:10:18 +08:00
parent 1c12b1d5b8
commit e214c2a8fd
@@ -200,7 +200,7 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
} }
++searchIndex ++searchIndex
} }
val source = bookSourceList[searchIndex] val source = bookSourceList.getOrNull(searchIndex) ?: return
bookSourceList[searchIndex] = emptyBookSource bookSourceList[searchIndex] = emptyBookSource
val task = execute( val task = execute(
context = searchPool!!, context = searchPool!!,
@@ -227,9 +227,11 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
} }
}.timeout(60000L) }.timeout(60000L)
.onError { .onError {
ensureActive()
nextSearch() nextSearch()
} }
.onSuccess { .onSuccess {
ensureActive()
nextSearch() nextSearch()
} }
task.start() task.start()
@@ -298,8 +300,9 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
searchCallback?.searchSuccess(searchBook) searchCallback?.searchSuccess(searchBook)
} }
@Synchronized
private fun nextSearch() { private fun nextSearch() {
synchronized(this) { kotlin.runCatching {
if (searchIndex < bookSourceList.lastIndex) { if (searchIndex < bookSourceList.lastIndex) {
search() search()
} else { } else {