|
|
@@ -40,8 +40,6 @@ class Coroutine<T>(
|
|
|
private var timeMillis: Long? = null
|
|
|
private var errorReturn: Result<T>? = null
|
|
|
|
|
|
- private var isCancelCalled = false
|
|
|
-
|
|
|
val isCancelled: Boolean
|
|
|
get() = job.isCancelled
|
|
|
|
|
|
@@ -116,8 +114,7 @@ class Coroutine<T>(
|
|
|
}
|
|
|
|
|
|
//取消当前任务
|
|
|
- fun cancel(cause: CancellationException? = null) {
|
|
|
- isCancelCalled = true
|
|
|
+ fun cancel(cause: ActivelyCancelException = ActivelyCancelException()) {
|
|
|
job.cancel(cause)
|
|
|
cancel?.let {
|
|
|
MainScope().launch {
|
|
|
@@ -149,7 +146,7 @@ class Coroutine<T>(
|
|
|
success?.let { dispatchCallback(this, value, it) }
|
|
|
} catch (e: Throwable) {
|
|
|
e.printOnDebug()
|
|
|
- if (e is CancellationException && !isCancelCalled) this@Coroutine.cancel()
|
|
|
+ if (e is ActivelyCancelException) this@Coroutine.cancel()
|
|
|
if (e is CancellationException && e !is TimeoutCancellationException) {
|
|
|
return@launch
|
|
|
}
|