This commit is contained in:
Horis
2023-07-24 22:49:14 +08:00
parent 61f929777e
commit 77ec679448
3 changed files with 15 additions and 15 deletions

View File

@@ -82,12 +82,13 @@ class SearchModel(private val scope: CoroutineScope, private val callBack: CallB
source,
searchKey,
searchPage,
context = searchPool
context = searchPool,
executeContext = searchPool
).timeout(30000L)
.onSuccess(searchPool) {
.onSuccess {
onSuccess(searchId, it)
}
.onFinally(searchPool) {
.onFinally {
onFinally(searchId)
}
tasks.add(task)

View File

@@ -30,8 +30,9 @@ object WebBook {
key: String,
page: Int? = 1,
context: CoroutineContext = Dispatchers.IO,
executeContext: CoroutineContext = Dispatchers.Main,
): Coroutine<ArrayList<SearchBook>> {
return Coroutine.async(scope, context) {
return Coroutine.async(scope, context, executeContext = executeContext) {
searchBookAwait(bookSource, key, page)
}
}

View File

@@ -192,7 +192,7 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
searchIndex++
}
val source = bookSourceList[searchIndex]
val task = Coroutine.async(scope = viewModelScope, context = searchPool!!) {
val task = execute(context = searchPool!!, executeContext = searchPool!!) {
val resultBooks = WebBook.searchBookAwait(source, name)
resultBooks.forEach { searchBook ->
if (searchBook.name != name) {
@@ -336,8 +336,8 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
searchIndex++
}
val searchBook = searchBookList[searchIndex]
val task = Coroutine.async(scope = viewModelScope, context = searchPool!!) {
val source = appDb.bookSourceDao.getBookSource(searchBook.origin) ?: return@async
val task = execute(context = searchPool!!, executeContext = searchPool!!) {
val source = appDb.bookSourceDao.getBookSource(searchBook.origin) ?: return@execute
loadBookInfo(source, searchBook.toBook())
}.timeout(60000L)
.onError {
@@ -438,15 +438,13 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
suspend fun getToc(book: Book): Result<Pair<List<BookChapter>, BookSource>> {
return kotlin.runCatching {
withContext(IO) {
val source = appDb.bookSourceDao.getBookSource(book.origin)
?: throw NoStackTraceException("书源不存在")
if (book.tocUrl.isEmpty()) {
WebBook.getBookInfoAwait(source, book)
}
val toc = WebBook.getChapterListAwait(source, book).getOrThrow()
Pair(toc, source)
val source = appDb.bookSourceDao.getBookSource(book.origin)
?: throw NoStackTraceException("书源不存在")
if (book.tocUrl.isEmpty()) {
WebBook.getBookInfoAwait(source, book)
}
val toc = WebBook.getChapterListAwait(source, book).getOrThrow()
Pair(toc, source)
}
}