How can I stop a live server?
Closed this issue · 5 comments
I've been testing this package out and so far so amazing!
I'm consuming a Flow and when it completes I would like to stop the live server as there are no further updates to send. How can I get a reference to the ApplicationServer in order to stop it?
I'm using https://github.com/mipt-npm/plotly.kt/blob/master/examples/src/main/kotlin/complexDynamicServer.kt as the starting point, but as an example instead of doing while(true)
on the flow producer I'm doing repeat(100)
Do I understand right that you want to close the server from inside the Plotsly.serve{}
closure? This is not supported right now, but it is possible in principle, so we can add it. Still, it does not make a lot of sense. The dynamic plot state is not saved in the browser, it will crash on the next reload if the server is turned off. So it makes sense to shut it down only when you close the application. Initial data could be embedded in the page via embeddData
flag, but it won't work for updated data.
Of course there a lot of possibilities here, so could you please state your case more clearly?
Ah yes that is a good point about reload. I think the issue that I'm really trying to solve is that I want the process as triggered by running the main function to be closed automatically. Inevitably this will shut down the process so your issue still stands.
It is just a bit of a frustration if you're iterating locally on something that produces results and if you just reload (ctrl-r in intellij idea) you get a port conflict error.
OK, I see your case.
I've added PlotlyServer::application
property, which exposes Ktor Application to Plotly via 811eed1. The cancelation should be then done via application.cancel()
. For now, I do not see a clear way to preserve the data if the server is stopped.
It does not work. It stops the inner scope but does not stop the application.
Then another solution for you. Move both traces and their update outside of serve
scope. Then you can close the application via its handle.
Move both traces and their update outside of serve scope
Ah this is a perfect solution and actually cleans things up a lot. Thanks!