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