29 lines
749 B
Kotlin
29 lines
749 B
Kotlin
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 }
|
|
}
|
|
|
|
class Controller {
|
|
suspend fun suspendHere(): Int = suspendCoroutineOrReturn { x ->
|
|
x.resume(42)
|
|
COROUTINE_SUSPENDED
|
|
}
|
|
}
|
|
|
|
fun builder(c: suspend Controller.() -> Unit) {
|
|
c.startCoroutine(Controller(), EmptyContinuation)
|
|
}
|
|
|
|
fun main(args: Array<String>) {
|
|
var result = 0
|
|
|
|
builder {
|
|
result = suspendHere()
|
|
}
|
|
|
|
println(result)
|
|
} |