Refine definition of whether call is suspension point

It's not about all calls to suspend functions, they may called from non-coroutine code
This commit is contained in:
Denis Zharkov
2016-06-01 12:53:14 +03:00
parent 1067531224
commit 2bdaec6eac
6 changed files with 86 additions and 10 deletions
@@ -0,0 +1,36 @@
class Controller {
suspend fun suspendHere(x: Continuation<String>) {
x.resume("OK")
}
}
fun builder(coroutine c: Controller.() -> Continuation<Unit>) {
c(Controller()).resume(Unit)
}
fun box(): String {
var result = "fail"
val lambda: Controller.() -> Continuation<Unit> = {
object : Continuation<Any?> {
override fun resume(data: Any?) {
if (data == Unit) {
suspendHere(this)
return
}
if (data != "OK") {
throw java.lang.RuntimeException("fail: $data")
}
result = "OK"
}
override fun resumeWithException(exception: Throwable) = throw exception
}
}
builder(lambda)
return result
}
@@ -0,0 +1,23 @@
class Controller {
suspend fun suspendHere(x: Continuation<String>) {
suspendThere(x)
}
suspend fun suspendThere(x: Continuation<String>) {
x.resume("OK")
}
}
fun builder(coroutine c: Controller.() -> Continuation<Unit>) {
c(Controller()).resume(Unit)
}
fun box(): String {
var result = ""
builder {
result = suspendHere()
}
return result
}