Laurent Thiebaud
06/21/2024, 12:48 PMRuntime.getRuntime().addShutdownHook(myShutdownHook);
simon.vergauwen
06/21/2024, 2:37 PMSuspendApp { }
variant on top of runBlocking
that does exactly this on top of Structured Concurrency.
So, if you receive a SIGTERM
or SIGINT
it will cancel
the CoroutineScope
, and it'll block the shutdown thread until the entire program is finished (CoroutineScope.join
).
This allows you to run finalisers, such as committing offsets to Kafka, stop(500, 500)
any network engine, clean-up, etc.
Side-note: it lives under the Arrow-kt umbrella, but it only has KotlinX Coroutines as a dependency.
https://github.com/arrow-kt/suspendappEmil Kantis
06/21/2024, 3:22 PM