From 6e9f77ac93bb995a5ca2a9a2ddc51f14359f6550 Mon Sep 17 00:00:00 2001 From: Horis <8674809+821938089@users.noreply.github.com> Date: Wed, 5 Feb 2025 16:54:09 +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 --- .../java/io/legado/app/help/coroutine/Coroutine.kt | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 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 2ca8ed9f6..879f88921 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 @@ -130,6 +130,11 @@ class Coroutine( block: suspend CoroutineScope.() -> Unit ): Coroutine { this.cancel = VoidCallback(context, block) + job.invokeOnCompletion { + if (it is CancellationException && it !is ActivelyCancelException) { + cancel() + } + } return this@Coroutine } @@ -156,11 +161,7 @@ class Coroutine( } fun start() { - if (startOption === CoroutineStart.LAZY && isCancelled) { - cancel() - } else { - job.start() - } + job.start() } private fun executeInternal( @@ -176,9 +177,6 @@ class Coroutine( success?.let { dispatchCallback(this, value, it) } } catch (e: Throwable) { e.printOnDebug() - if (e is CancellationException && e !is ActivelyCancelException && isCancelled) { - this@Coroutine.cancel() - } val consume: Boolean = errorReturn?.value?.let { value -> success?.let { dispatchCallback(this, value, it) } true