Deactivated User
12/23/2016, 12:07 PMclass CoExample {
companion object {
@JvmStatic fun main(args: Array<String>) {
CoExample().entry()
}
}
fun entry() {
val demoMethod = CoExample::class.java.declaredMethods.first { it.name == "demo" }
val value = -1 // doesn't show anything (because negative branch doesn't suspend)
//val value = +1 // shows possitive
val result = demoMethod.invoke(this, value, object : Continuation<String> {
override fun resume(value: String) = println(value)
override fun resumeWithException(exception: Throwable) = throw exception
})
if (result != CoroutineIntrinsics.SUSPENDED) {
println(result)
}
EventLoop.impl.step()
Thread.sleep(100L)
}
suspend fun demo(a: Int): String= awaitAsync {
if (a < 0) {
"negative"
} else {
sleep(10)
"possitive"
}
}
}