Support suspend fun main in JVM

#KT-17679 Fixed
This commit is contained in:
Denis Zharkov
2018-09-06 11:21:10 +03:00
parent 272ee252d8
commit c3f6ba3302
11 changed files with 233 additions and 1 deletions
@@ -0,0 +1 @@
Return code: 0
@@ -0,0 +1,35 @@
package Hello
import kotlin.concurrent.thread
import kotlin.coroutines.suspendCoroutine
import kotlin.coroutines.resume
@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(args: Array<String>) {
thread(isDaemon = true) {
while (true) {
val c = callback
c?.invoke()
Thread.sleep(500)
}
}
appendAndSuspend(args[0])
appendAndSuspend(args[1])
println(result)
callback = null
}
@@ -0,0 +1,4 @@
OUT:
OK
Return code: 0