|
|
@ -4,7 +4,9 @@ import kotlinx.coroutines.* |
|
|
|
import timber.log.Timber |
|
|
|
import timber.log.Timber |
|
|
|
import kotlin.coroutines.CoroutineContext |
|
|
|
import kotlin.coroutines.CoroutineContext |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 链式协程 |
|
|
|
|
|
|
|
*/ |
|
|
|
@Suppress("unused") |
|
|
|
@Suppress("unused") |
|
|
|
class Coroutine<T>( |
|
|
|
class Coroutine<T>( |
|
|
|
val scope: CoroutineScope, |
|
|
|
val scope: CoroutineScope, |
|
|
@ -146,21 +148,17 @@ class Coroutine<T>( |
|
|
|
} catch (e: Throwable) { |
|
|
|
} catch (e: Throwable) { |
|
|
|
Timber.e(e) |
|
|
|
Timber.e(e) |
|
|
|
val consume: Boolean = errorReturn?.value?.let { value -> |
|
|
|
val consume: Boolean = errorReturn?.value?.let { value -> |
|
|
|
if (isActive) { |
|
|
|
|
|
|
|
success?.let { dispatchCallback(this, value, it) } |
|
|
|
success?.let { dispatchCallback(this, value, it) } |
|
|
|
} |
|
|
|
|
|
|
|
true |
|
|
|
true |
|
|
|
} ?: false |
|
|
|
} ?: false |
|
|
|
if (!consume && isActive) { |
|
|
|
if (!consume) { |
|
|
|
error?.let { dispatchCallback(this, e, it) } |
|
|
|
error?.let { dispatchCallback(this, e, it) } |
|
|
|
} |
|
|
|
} |
|
|
|
} finally { |
|
|
|
} finally { |
|
|
|
if (isActive) { |
|
|
|
|
|
|
|
finally?.let { dispatchVoidCallback(this, it) } |
|
|
|
finally?.let { dispatchVoidCallback(this, it) } |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private suspend inline fun dispatchVoidCallback(scope: CoroutineScope, callback: VoidCallback) { |
|
|
|
private suspend inline fun dispatchVoidCallback(scope: CoroutineScope, callback: VoidCallback) { |
|
|
|
if (null == callback.context) { |
|
|
|
if (null == callback.context) { |
|
|
|