Is there a way to shutdown the cats effect runtime from within an application, similar to System.exit(0)?
There is a shutdown method on IORuntime but it is not documented and it behaves weirdly when I call it on IORuntime.global: it does not shut the application down, it just seems to hang it. Also accessing runtime on my IOApp just throws a NullPointerException so I cannot use that. What I want to do is: from within my application a want to make the complete runtime shutdown cleanly, i.e. cancelling the main fiber and running all finalisers. I know I can implement such a shutdown-hook myself, but I was wondering if that is already supported somehow by cats effect, which is what the existence of these methods suggest.
You can do something like (pseudocode)
Inside your app code, it can call
shutdown.complete(()). TheIO.racewill run both fibers until one completes, then cancel the other. TheuseForevermeans your app won't close on its own, and theshutdown.getwill wait until it's completed. So when your app callsshutdown.complete, theappresource will be interrupted and cancelled, letting the program exit after doing a clean resource release