32 lines
754 B
Kotlin
32 lines
754 B
Kotlin
package codegen.coroutines.withReceiver
|
|
|
|
import kotlin.test.*
|
|
|
|
import kotlin.coroutines.*
|
|
import kotlin.coroutines.intrinsics.*
|
|
|
|
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
|
companion object : EmptyContinuation()
|
|
override fun resumeWith(result: SuccessOrFailure<Any?>) { result.getOrThrow() }
|
|
}
|
|
|
|
class Controller {
|
|
suspend fun suspendHere(): Int = suspendCoroutineUninterceptedOrReturn { x ->
|
|
x.resume(42)
|
|
COROUTINE_SUSPENDED
|
|
}
|
|
}
|
|
|
|
fun builder(c: suspend Controller.() -> Unit) {
|
|
c.startCoroutine(Controller(), EmptyContinuation)
|
|
}
|
|
|
|
@Test fun runTest() {
|
|
var result = 0
|
|
|
|
builder {
|
|
result = suspendHere()
|
|
}
|
|
|
|
println(result)
|
|
} |