现在超时不会触发取消任务了,onFinal会正常触发,取消任务的时候不触发onFinal,防止服务退出后仍然执行onFinal

pull/2121/head
kunfei 2 years ago
parent 97b74d9c98
commit 1bcbae9de7
  1. 4
      app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt

@ -148,7 +148,7 @@ class Coroutine<T>(
success?.let { dispatchCallback(this, value, it) }
} catch (e: Throwable) {
e.printOnDebug()
if (e is CancellationException && !isActive && e !is ActivelyCancelException) {
if (e is CancellationException && e !is ActivelyCancelException && isCancelled) {
this@Coroutine.cancel()
}
val consume: Boolean = errorReturn?.value?.let { value ->
@ -159,12 +159,10 @@ class Coroutine<T>(
error?.let { dispatchCallback(this, e, it) }
}
} finally {
withContext(NonCancellable) {
finally?.let { dispatchVoidCallback(this, it) }
}
}
}
}
private suspend inline fun dispatchVoidCallback(scope: CoroutineScope, callback: VoidCallback) {
if (null == callback.context) {

Loading…
Cancel
Save