I am working on a Racket web server. Having used Clojure in the past, I quite like being able to have convenience procedures for working within my code.
Particularly, I want to implement a (start-server!) and a (stop-server!) procedure that enable me to start / stop the web-server within the current REPL.
Check me on this: when you run serve/servlet without the thread wrapper, it returns immediately after starting the server, right? Assuming so: the thread you started will die as soon as the call to serve/servlet returns. You can probably also check this by calling thread-dead?before you call stop-server!. I believe you will find that the thread dies immediately when the server starts up.
In order to get the behavior you want, I suspect you will either need to
find a function in the web-server interface that lets you inspect and halt running server instances, or
start the server with a lower-level blocking call that does not immediately return, but actually runs the (main?) web server thread on the current thread.
There are other heavier-handed approaches, e.g. custodians or literally running another process using process or system or similar.
... But I bet there's a way to do this using only web server functions.
You want one of the procedures listed here: 3 Launching Servers . My preference is to always use serve, which returns a procedure that can be used to stop the server. This post might also be helpful.
Also, generally, kill-thread should be avoided unless you know (i.e. the documentation mentions) that the data structures used by the thread you're killing are kill-safe.