How can we use automatic reloading?

1.9k views Asked by At

Trying to utilise the automatic module reloading feature (as described here), but the documentation is unfortunately not too helpful.

It says to use configuration, but the configuration page is empty.

I believe you can pass in the "watch" list of modules into the embeddedServer() call from this page, but when I do, I get the following exception: Module function provided as lambda cannot be unlinked for reload.

So it won't let you pass in a lambda as an application module, but then I'm not sure how to avoid doing that while getting access to the Application methods (e.g. routing()).

Has anyone been able to get automatic reloading working lately? If so, how?

1

There are 1 answers

0
Ilya Ryzhenkov On BEST ANSWER

Lambda might have a captured state from containing function and thus cannot be reloaded – there is no way to restore the captured state. You have to extract application into a separate function like this:

fun Application.module() {
   install(CallLogging)
   install(Routing) {
      get("/") {
        call.respondText("""Hello, world!<br><a href="/bye">Say bye?</a>""", ContentType.Text.Html)
      }
    …
   }
}

And then start it with function reference:

embeddedServer(Jetty, watchPaths = listOf("embedded"), module = Application::module).start()