Minor. Get rid of code duplications for resume call wrapping in stdlib
Use processBareContinuationResume instead
This commit is contained in:
@@ -15,7 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
package kotlin.coroutines.experimental
|
package kotlin.coroutines.experimental
|
||||||
|
|
||||||
import kotlin.coroutines.experimental.intrinsics.*
|
import kotlin.coroutines.experimental.intrinsics.*
|
||||||
|
|
||||||
internal fun <R, T> (suspend R.() -> T).createCoroutineInternal(
|
internal fun <R, T> (suspend R.() -> T).createCoroutineInternal(
|
||||||
@@ -51,17 +50,7 @@ internal abstract class CoroutineImpl(private val resultContinuation: Continuati
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected fun doResumeWrapper() {
|
protected fun doResumeWrapper() {
|
||||||
try {
|
processBareContinuationResume(resultContinuation) { doResume() }
|
||||||
result = doResume()
|
|
||||||
if (result !== COROUTINE_SUSPENDED) {
|
|
||||||
val data = result
|
|
||||||
result = COROUTINE_SUSPENDED
|
|
||||||
resultContinuation.resume(data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (e: Throwable) {
|
|
||||||
resultContinuation.resumeWithException(e)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract fun doResume(): Any?
|
protected abstract fun doResume(): Any?
|
||||||
|
|||||||
@@ -90,11 +90,11 @@ public inline suspend fun <T> suspendCoroutine(crossinline block: (Continuation<
|
|||||||
|
|
||||||
// INTERNAL DECLARATIONS
|
// INTERNAL DECLARATIONS
|
||||||
|
|
||||||
internal inline fun processInvokeCallOnCoroutine(completion: Continuation<*>, block: () -> Any?) {
|
@kotlin.internal.InlineOnly
|
||||||
|
internal inline fun processBareContinuationResume(completion: Continuation<*>, block: () -> Any?) {
|
||||||
try {
|
try {
|
||||||
val result = block()
|
val result = block()
|
||||||
if (result !== COROUTINE_SUSPENDED) {
|
if (result !== COROUTINE_SUSPENDED) {
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
(completion as Continuation<Any?>).resume(result)
|
(completion as Continuation<Any?>).resume(result)
|
||||||
}
|
}
|
||||||
} catch (t: Throwable) {
|
} catch (t: Throwable) {
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ private inline fun <T> buildContinuationByInvokeCall(
|
|||||||
get() = completion.context
|
get() = completion.context
|
||||||
|
|
||||||
override fun resume(value: Unit) {
|
override fun resume(value: Unit) {
|
||||||
processInvokeCallOnCoroutine(completion, block)
|
processBareContinuationResume(completion, block)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun resumeWithException(exception: Throwable) {
|
override fun resumeWithException(exception: Throwable) {
|
||||||
|
|||||||
@@ -18,10 +18,7 @@
|
|||||||
package kotlin.coroutines.experimental.jvm.internal
|
package kotlin.coroutines.experimental.jvm.internal
|
||||||
|
|
||||||
import java.lang.IllegalStateException
|
import java.lang.IllegalStateException
|
||||||
import kotlin.coroutines.experimental.Continuation
|
import kotlin.coroutines.experimental.*
|
||||||
import kotlin.coroutines.experimental.ContinuationInterceptor
|
|
||||||
import kotlin.coroutines.experimental.CoroutineContext
|
|
||||||
import kotlin.coroutines.experimental.intrinsics.COROUTINE_SUSPENDED
|
|
||||||
import kotlin.coroutines.experimental.jvm.internal.interceptContinuationIfNeeded
|
import kotlin.coroutines.experimental.jvm.internal.interceptContinuationIfNeeded
|
||||||
import kotlin.jvm.internal.Lambda
|
import kotlin.jvm.internal.Lambda
|
||||||
|
|
||||||
@@ -49,22 +46,14 @@ abstract class CoroutineImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun resume(value: Any?) {
|
override fun resume(value: Any?) {
|
||||||
try {
|
processBareContinuationResume(completion!!) {
|
||||||
val result = doResume(value, null)
|
doResume(value, null)
|
||||||
if (result !== COROUTINE_SUSPENDED)
|
|
||||||
completion!!.resume(result)
|
|
||||||
} catch (e: Throwable) {
|
|
||||||
completion!!.resumeWithException(e)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun resumeWithException(exception: Throwable) {
|
override fun resumeWithException(exception: Throwable) {
|
||||||
try {
|
processBareContinuationResume(completion!!) {
|
||||||
val result = doResume(null, exception)
|
doResume(null, exception)
|
||||||
if (result !== COROUTINE_SUSPENDED)
|
|
||||||
completion!!.resume(result)
|
|
||||||
} catch (e: Throwable) {
|
|
||||||
completion!!.resumeWithException(e)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user