31 lines
734 B
Kotlin
31 lines
734 B
Kotlin
package codegen.coroutines.simple
|
|
|
|
import kotlin.test.*
|
|
|
|
import kotlin.coroutines.experimental.*
|
|
import kotlin.coroutines.experimental.intrinsics.*
|
|
|
|
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
|
companion object : EmptyContinuation()
|
|
override fun resume(value: Any?) {}
|
|
override fun resumeWithException(exception: Throwable) { throw exception }
|
|
}
|
|
|
|
suspend fun suspendHere(): Int = suspendCoroutineOrReturn { x ->
|
|
x.resume(42)
|
|
COROUTINE_SUSPENDED
|
|
}
|
|
|
|
fun builder(c: suspend () -> Unit) {
|
|
c.startCoroutine(EmptyContinuation)
|
|
}
|
|
|
|
@Test fun runTest() {
|
|
var result = 0
|
|
|
|
builder {
|
|
result = suspendHere()
|
|
}
|
|
|
|
println(result)
|
|
} |