Started using SuspendApp and suspend-app-ktor, and...
# arrow
d
Started using SuspendApp and suspend-app-ktor, and I'm getting this:
Copy code
5
2023-02-23 14:45:43.454 [DefaultDispatcher-worker-2] INFO ktor.application - prewait delay of 30000ms, turn it off using io.ktor.development=true
4
2023-02-23 14:46:13.455 [DefaultDispatcher-worker-2] INFO ktor.application - Shutting down HTTP server...
3
2023-02-23 14:46:13.962 [DefaultDispatcher-worker-2] INFO ktor.application - Application stopping: io.ktor.server.application.Application@6da73151
2
2023-02-23 14:46:13.963 [DefaultDispatcher-worker-2] INFO ktor.application - Application stopped: io.ktor.server.application.Application@6da73151
1
2023-02-23 14:46:13.966 [DefaultDispatcher-worker-2] INFO ktor.application - HTTP server shutdown!
right after Ktor was already ready to receive connections! Why is it closing down like that?
s
You're probably immediately terminating the application, you need to
awaitCancellation
of the
SuspendApp
. https://github.com/nomisRev/ktor-arrow-example/blob/efb93311e4a0d2db47ecb1c134e0ec0f922d7d2d/src/main/kotlin/io/github/nomisrev/main.kt#L21 Similarly to how you would otherwise call
start(wait = true)
.
d
Copy code
fun main() = SuspendApp {
    resourceScope {
        val appConfigs = getAppConfig {
            addResourceSource("/application.yml")
            addResourceSource("/application-dev.yml", true)
            addEnvironmentSource()
        }

        val appResources = appResources(appConfigs)

        server(
            Netty, port = 8080, host = "0.0.0.0",
            module = AppComponent::class.create(appResources, appConfigs).appModule
        )
    }
    awaitCancellation()
}
That's what I have
s
You're calling it outside of the
resourceScope
so the
resourceScope
and thus the
server
terminates.
d
Thanks!