Files
kotlin-fork/compiler/testData/integration/smoke/helloAppSuspendParameterlessMain/hello.kt
T
Denis Zharkov bc722f9c5f Support main entry-point without arguments in JVM
#KT-26574 In Progress
2018-09-12 09:48:13 +03:00

37 lines
722 B
Kotlin
Vendored

package Hello
import kotlin.concurrent.thread
import kotlin.coroutines.suspendCoroutine
import kotlin.coroutines.resume
import kotlin.reflect.jvm.javaMethod
@kotlin.jvm.Volatile
private var result = ""
@kotlin.jvm.Volatile
private var callback: Function0<Unit>? = null
suspend fun appendAndSuspend(s: String) {
result += s
suspendCoroutine<Unit> { continuation ->
callback = {
continuation.resume(Unit)
}
}
}
suspend fun main() {
thread(isDaemon = true) {
while (true) {
val c = callback
c?.invoke()
Thread.sleep(500)
}
}
appendAndSuspend("O")
appendAndSuspend("K")
println(result)
callback = null
}