Hello, I'm using IntelliJ to try out coroutines on...
# coroutines
e
Hello, I'm using IntelliJ to try out coroutines on the JVM. I have a pretty simple method that calls
GlobalScope.launch
, awaits a deferred value, prints its contents, and then outside of the launch method, prints a concluding String. All of this is working great. The process is still running when these two print tasks complete however. What is keeping it alive, and can I gracefully shutdown when all my work has been completed? Edit: Updated code block from Louis' comments
Copy code
suspend fun main() {
    val api = createRestApi<RestApi>("<https://catfact.ninja/>", okHttpClient(), moshi)

    coroutineScope {
        val facts = api.getFacts().await()
        println(facts.data)
    }
    println("That's all")
}
l
You should wrap with
coroutineScope { … }
instead of using
GlobalScope
Then you'd not event need
launch
and
join
e
I've updated the function and it looks much nicer (and is now structured). The process is still running after "Thats all" is printed however
s
✔️ 1