优化
This commit is contained in:
@@ -130,6 +130,11 @@ class Coroutine<T>(
|
|||||||
block: suspend CoroutineScope.() -> Unit
|
block: suspend CoroutineScope.() -> Unit
|
||||||
): Coroutine<T> {
|
): Coroutine<T> {
|
||||||
this.cancel = VoidCallback(context, block)
|
this.cancel = VoidCallback(context, block)
|
||||||
|
job.invokeOnCompletion {
|
||||||
|
if (it is CancellationException && it !is ActivelyCancelException) {
|
||||||
|
cancel()
|
||||||
|
}
|
||||||
|
}
|
||||||
return this@Coroutine
|
return this@Coroutine
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,11 +161,7 @@ class Coroutine<T>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun start() {
|
fun start() {
|
||||||
if (startOption === CoroutineStart.LAZY && isCancelled) {
|
job.start()
|
||||||
cancel()
|
|
||||||
} else {
|
|
||||||
job.start()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun executeInternal(
|
private fun executeInternal(
|
||||||
@@ -176,9 +177,6 @@ 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 && e !is ActivelyCancelException && isCancelled) {
|
|
||||||
this@Coroutine.cancel()
|
|
||||||
}
|
|
||||||
val consume: Boolean = errorReturn?.value?.let { value ->
|
val consume: Boolean = errorReturn?.value?.let { value ->
|
||||||
success?.let { dispatchCallback(this, value, it) }
|
success?.let { dispatchCallback(this, value, it) }
|
||||||
true
|
true
|
||||||
|
|||||||
Reference in New Issue
Block a user