mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-08 08:31:26 +00:00
33 lines
634 B
Kotlin
Vendored
33 lines
634 B
Kotlin
Vendored
// WITH_RUNTIME
|
|
// WITH_COROUTINES
|
|
import helpers.*
|
|
import kotlin.coroutines.experimental.*
|
|
import kotlin.coroutines.experimental.intrinsics.*
|
|
|
|
var globalResult = ""
|
|
suspend fun suspendWithValue(v: String): String = suspendCoroutineOrReturn { x ->
|
|
x.resume(v)
|
|
COROUTINE_SUSPENDED
|
|
}
|
|
|
|
fun builder(c: suspend () -> String) {
|
|
c.startCoroutine(handleResultContinuation {
|
|
globalResult = it
|
|
})
|
|
}
|
|
|
|
fun box(): String {
|
|
|
|
var condition = true
|
|
|
|
builder {
|
|
if (condition) {
|
|
suspendWithValue("OK")
|
|
} else {
|
|
suspendWithValue("fail 1")
|
|
}
|
|
}
|
|
|
|
return globalResult
|
|
}
|