I’m pretty new to Kotlin coroutines and I’ve faced a problem with calling an asynchronious function in main
. The program below looks nice, except exitProcess
call. Without it the JVM can’t exit.
package io.github.commandertvis.boredapi
import io.github.rybalkinsd.kohttp.dsl.async.httpGetAsync
import io.github.rybalkinsd.kohttp.ext.url
import java.net.URL
import kotlin.system.exitProcess
suspend fun main() {
println(httpGetAsync { url(URL("http://www.boredapi.com/api/activity")) }
.await()
.use { it.body()!!.string() })
exitProcess(0)
}
How can I improve this code?