At several points of my program, I use launch to start a coroutine that does some background tasks. Then, at some point, I return from the main function. A simplified version of my program could look like this:
fun main(args : Array<String>)
{
launch {
delay(10000) // some long running operation
println("finished")
}
}
Now, the coroutine starts as expected and starts running the operation - and then the program exits. If I don't return from main or replace launch with thread, everything works as expected. So how can I, given that I don't keep track of all coroutines started in my program (hence I cannot use .join() or .await()), make sure that all coroutines finish before my program exits?