From 01af2c35b5a168d26790fa2f257c6e541a09452b Mon Sep 17 00:00:00 2001 From: 821938089 <821938089@qq.com> Date: Wed, 27 Jul 2022 07:57:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 01612b877..36a21428c 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 @@ -40,6 +40,8 @@ class Coroutine( private var timeMillis: Long? = null private var errorReturn: Result? = null + private var isCancelCalled = false + val isCancelled: Boolean get() = job.isCancelled @@ -115,6 +117,7 @@ class Coroutine( //取消当前任务 fun cancel(cause: CancellationException? = null) { + isCancelCalled = true job.cancel(cause) cancel?.let { MainScope().launch { @@ -146,8 +149,8 @@ class Coroutine( success?.let { dispatchCallback(this, value, it) } } catch (e: Throwable) { e.printOnDebug() + if (e is CancellationException && !isCancelCalled) this@Coroutine.cancel() if (e is CancellationException && e !is TimeoutCancellationException) { - this@Coroutine.cancel() return@launch } val consume: Boolean = errorReturn?.value?.let { value ->