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:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user