Skip to content

Commit

Permalink
feat: ApplicationEngine shutdown hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
LizAinslie committed Nov 11, 2024
1 parent f6df411 commit 28d2513
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ import sh.illumi.kraft.util.argsMatchParams
abstract class ApplicationEngine {
lateinit var rootLayer: ApplicationLayer private set

fun registerShutdownHook() {
Runtime.getRuntime().addShutdownHook(Thread {
rootLayer.shutdown()
})
}

fun <TLayer : ApplicationLayer> startRoot(createRoot: suspend CoroutineScope.() -> ApplicationLayer) = runBlocking {
rootLayer = createRoot()
rootLayer.start()
Expand Down

0 comments on commit 28d2513

Please sign in to comment.