优化
This commit is contained in:
@@ -200,11 +200,9 @@ class Coroutine<T>(
|
||||
|
||||
private suspend inline fun dispatchVoidCallback(scope: CoroutineScope, callback: VoidCallback) {
|
||||
if (null == callback.context) {
|
||||
withContext(scope.coroutineContext) {
|
||||
callback.block.invoke(scope)
|
||||
}
|
||||
} else {
|
||||
withContext(scope.coroutineContext + callback.context) {
|
||||
withContext(callback.context) {
|
||||
callback.block.invoke(this)
|
||||
}
|
||||
}
|
||||
@@ -219,7 +217,7 @@ class Coroutine<T>(
|
||||
if (null == callback.context) {
|
||||
callback.block.invoke(scope, value)
|
||||
} else {
|
||||
withContext(scope.coroutineContext + callback.context) {
|
||||
withContext(callback.context) {
|
||||
callback.block.invoke(this, value)
|
||||
}
|
||||
}
|
||||
@@ -231,7 +229,7 @@ class Coroutine<T>(
|
||||
timeMillis: Long,
|
||||
noinline block: suspend CoroutineScope.() -> T
|
||||
): T {
|
||||
return withContext(scope.coroutineContext + context) {
|
||||
return withContext(context) {
|
||||
if (timeMillis > 0L) withTimeout(timeMillis) {
|
||||
block()
|
||||
} else {
|
||||
@@ -242,12 +240,12 @@ class Coroutine<T>(
|
||||
|
||||
private data class Result<out T>(val value: T?)
|
||||
|
||||
private inner class VoidCallback(
|
||||
private class VoidCallback(
|
||||
val context: CoroutineContext?,
|
||||
val block: suspend CoroutineScope.() -> Unit
|
||||
)
|
||||
|
||||
private inner class Callback<VALUE>(
|
||||
private class Callback<VALUE>(
|
||||
val context: CoroutineContext?,
|
||||
val block: suspend CoroutineScope.(VALUE) -> Unit
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user