How to stop a server created using Mux?


#1

Eg :

using Mux

@app test = (
  Mux.defaults,
  page(respond("<h1>Yo!</h1>")),
  page("/about", probabilty(0.5, respond("<h1>Boo tati!</h1>")),
  respond("<h1>About Me</h1>")),
  page("/user/:user", req -> "<h1>Hello, $(req[:params][:user])!</h1>"),
  Mux.notfound())

  #route("/about", respond("<h1>Hello World!</h1>")),
  #route("/prince", respond("<h1>Hello Prince!</h1>")),

serve(test)

How to stop this server ? So that I can create a new one at the same address. Now, if I try to create a new without stopping current one it raises an error - listen: address already in use (EADDRINUSE) .


#2

From a cursory look, I don’t believe there is any way to do so. Mux puts an async closure onto the event loop and doesn’t return any references to the socket or server task. You would need to return a handle to the task, and throwto it to stop the server.


#3

Note that you may not need to, depending on your goal. @app is designed such that you can re-evaluate it and it will modify the server on the fly, so you shouldn’t need to kill the server to test changes.