From 120a3a870681c580db47d017e9f8ffc66cd94321 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 14 Feb 2022 17:28:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=A0=A1=E9=AA=8C=E8=B6=85?= =?UTF-8?q?=E6=97=B6=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/help/coroutine/Coroutine.kt | 5 +++-- .../io/legado/app/service/CheckSourceService.kt | 13 ++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt b/app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt index 06c02f1a1..70664c1d4 100644 --- a/app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt +++ b/app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt @@ -143,10 +143,11 @@ class Coroutine( val value = executeBlock(scope, context, timeMillis ?: 0L, block) ensureActive() success?.let { dispatchCallback(this, value, it) } - } catch (e: CancellationException) { - Timber.e("任务取消") } catch (e: Throwable) { Timber.e(e) + if (e is CancellationException && e !is TimeoutCancellationException) { + return@launch + } val consume: Boolean = errorReturn?.value?.let { value -> success?.let { dispatchCallback(this, value, it) } true diff --git a/app/src/main/java/io/legado/app/service/CheckSourceService.kt b/app/src/main/java/io/legado/app/service/CheckSourceService.kt index e865b9f00..3f56a86d9 100644 --- a/app/src/main/java/io/legado/app/service/CheckSourceService.kt +++ b/app/src/main/java/io/legado/app/service/CheckSourceService.kt @@ -8,11 +8,9 @@ import io.legado.app.constant.AppConst import io.legado.app.constant.EventBus import io.legado.app.constant.IntentAction import io.legado.app.data.appDb -import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.Book -import io.legado.app.data.entities.SearchBook +import io.legado.app.data.entities.BookSource import io.legado.app.help.AppConfig -import io.legado.app.help.coroutine.CompositeCoroutine import io.legado.app.model.* import io.legado.app.model.webBook.WebBook import io.legado.app.ui.book.source.manage.BookSourceActivity @@ -23,14 +21,17 @@ import io.legado.app.utils.toastOnUi import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.TimeoutCancellationException import kotlinx.coroutines.asCoroutineDispatcher +import kotlinx.coroutines.launch import java.util.concurrent.Executors import kotlin.math.min +/** + * 校验书源 + */ class CheckSourceService : BaseService() { private var threadCount = AppConfig.threadCount private var searchCoroutine = Executors.newFixedThreadPool(min(threadCount, AppConst.MAX_THREAD)).asCoroutineDispatcher() - private var tasks = CompositeCoroutine() private val allIds = ArrayList() private val checkedIds = ArrayList() private var processIndex = 0 @@ -71,7 +72,6 @@ class CheckSourceService : BaseService() { override fun onDestroy() { super.onDestroy() Debug.finishChecking() - tasks.clear() searchCoroutine.close() postEvent(EventBus.CHECK_SOURCE_DONE, 0) } @@ -81,7 +81,6 @@ class CheckSourceService : BaseService() { toastOnUi("已有书源在校验,等完成后再试") return } - tasks.clear() allIds.clear() checkedIds.clear() allIds.addAll(ids) @@ -102,7 +101,7 @@ class CheckSourceService : BaseService() { synchronized(this) { processIndex++ } - execute(context = searchCoroutine) { + launch(IO) { if (index < allIds.size) { val sourceUrl = allIds[index] appDb.bookSourceDao.getBookSource(sourceUrl)?.let { source ->