|
|
@ -19,7 +19,7 @@ class Coroutine<T>() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private var interceptor: Coroutine<T>? = null |
|
|
|
private var interceptor: Coroutine<T>? = null |
|
|
|
private var job: Job? = null |
|
|
|
private lateinit var job: Job |
|
|
|
|
|
|
|
|
|
|
|
private var start: (suspend CoroutineScope.() -> Unit)? = null |
|
|
|
private var start: (suspend CoroutineScope.() -> Unit)? = null |
|
|
|
private var execute: (suspend CoroutineScope.(T?) -> Unit)? = null |
|
|
|
private var execute: (suspend CoroutineScope.(T?) -> Unit)? = null |
|
|
@ -32,13 +32,13 @@ class Coroutine<T>() { |
|
|
|
private var errorReturn: Result<T>? = null |
|
|
|
private var errorReturn: Result<T>? = null |
|
|
|
|
|
|
|
|
|
|
|
val isCancelled: Boolean |
|
|
|
val isCancelled: Boolean |
|
|
|
get() = job?.isCancelled ?: false |
|
|
|
get() = job.isCancelled |
|
|
|
|
|
|
|
|
|
|
|
val isActive: Boolean |
|
|
|
val isActive: Boolean |
|
|
|
get() = job?.isActive ?: true |
|
|
|
get() = job.isActive |
|
|
|
|
|
|
|
|
|
|
|
val isCompleted: Boolean |
|
|
|
val isCompleted: Boolean |
|
|
|
get() = job?.isCompleted ?: false |
|
|
|
get() = job.isCompleted |
|
|
|
|
|
|
|
|
|
|
|
private constructor( |
|
|
|
private constructor( |
|
|
|
scope: CoroutineScope, |
|
|
|
scope: CoroutineScope, |
|
|
@ -119,7 +119,11 @@ class Coroutine<T>() { |
|
|
|
|
|
|
|
|
|
|
|
//取消当前任务 |
|
|
|
//取消当前任务 |
|
|
|
fun cancel(cause: CancellationException? = null) { |
|
|
|
fun cancel(cause: CancellationException? = null) { |
|
|
|
job?.cancel(cause) |
|
|
|
job.cancel(cause) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun invokeOnCompletion(handler: CompletionHandler): DisposableHandle{ |
|
|
|
|
|
|
|
return job.invokeOnCompletion(handler) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private suspend fun executeInternal(scope: CoroutineScope, block: suspend CoroutineScope.() -> T) { |
|
|
|
private suspend fun executeInternal(scope: CoroutineScope, block: suspend CoroutineScope.() -> T) { |
|
|
@ -134,6 +138,7 @@ class Coroutine<T>() { |
|
|
|
success?.invoke(scope, value) |
|
|
|
success?.invoke(scope, value) |
|
|
|
true |
|
|
|
true |
|
|
|
} ?: false |
|
|
|
} ?: false |
|
|
|
|
|
|
|
|
|
|
|
if (!consume) { |
|
|
|
if (!consume) { |
|
|
|
error?.invoke(scope, e) |
|
|
|
error?.invoke(scope, e) |
|
|
|
} |
|
|
|
} |
|
|
|