Hi all, how to safely close resources (http connec...
# coroutines
a
Hi all, how to safely close resources (http connections e.t.c.) while using coroutines? As far as my understanding goes, Dispatchers such as IO and Default are using demon threads which will be immediately shutdown when VM halts. So we can't be 100% shure if resource was closed in time or not.
u
I would expect the os to close your resources if your process dies. You would still have issues with deleting resources (e.g. temp files)
g
try/finally, as with any other JVM code will work
Http connection is probably better handle on level of coroutines cancellation
u
@gildor, neither cancellation nor finally will help if your process is terminated due to completion of all non demon threads. But as said above, then there is also no need to manually close os resources like files and sockets
g
I see what you mean, but looks that issue that there is no entry point in your app which will gracefully shutdown all the jobs in your main thread If entry point starts all coroutines and all those coroutines use structured concurrency, you can properly cancel them and clean all the resources
👍 1