pull/2119/head
kunfei 2 years ago
parent 8779e86f9e
commit 657b8dd5b4
  1. 4
      app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt
  2. 9
      app/src/main/java/io/legado/app/service/CheckSourceService.kt

@ -115,7 +115,9 @@ class Coroutine<T>(
//取消当前任务 //取消当前任务
fun cancel(cause: ActivelyCancelException = ActivelyCancelException()) { fun cancel(cause: ActivelyCancelException = ActivelyCancelException()) {
if (!job.isCancelled) {
job.cancel(cause) job.cancel(cause)
}
cancel?.let { cancel?.let {
MainScope().launch { MainScope().launch {
if (null == it.context) { if (null == it.context) {
@ -146,7 +148,7 @@ class Coroutine<T>(
success?.let { dispatchCallback(this, value, it) } success?.let { dispatchCallback(this, value, it) }
} catch (e: Throwable) { } catch (e: Throwable) {
e.printOnDebug() e.printOnDebug()
if (e is CancellationException && isActive) { if (e is CancellationException && !isActive && e !is ActivelyCancelException) {
this@Coroutine.cancel() this@Coroutine.cancel()
} }
if (e is CancellationException && e !is TimeoutCancellationException) { if (e is CancellationException && e !is TimeoutCancellationException) {

@ -190,15 +190,6 @@ class CheckSourceService : BaseService() {
}.onSuccess(searchCoroutine) { }.onSuccess(searchCoroutine) {
source.removeGroup("校验超时") source.removeGroup("校验超时")
Debug.updateFinalMessage(source.bookSourceUrl, "校验成功") Debug.updateFinalMessage(source.bookSourceUrl, "校验成功")
}.onCancel(IO) {
source.addGroup("校验超时")
source.bookSourceComment =
"Error: 校验超时" + if (source.bookSourceComment.isNullOrBlank())
"" else "\n\n${source.bookSourceComment}"
Debug.updateFinalMessage(source.bookSourceUrl, "校验失败: 校验超时")
source.respondTime = Debug.getRespondTime(source.bookSourceUrl)
appDb.bookSourceDao.update(source)
onNext(source.bookSourceUrl, source.bookSourceName)
}.onFinally(IO) { }.onFinally(IO) {
source.respondTime = Debug.getRespondTime(source.bookSourceUrl) source.respondTime = Debug.getRespondTime(source.bookSourceUrl)
appDb.bookSourceDao.update(source) appDb.bookSourceDao.update(source)

Loading…
Cancel
Save