Consider the following scenario:
A minimal boot task starts up a http server:
(boot (serve :handler 'myapp.server/handler
:port 3000))
(This might be launched in several ways, here it's ok to just run it from a nrepl session, e.g. started by boot repl
from the terminal)
The handler is represented by the function handler
inside the namespace myapp.server
. The corresponding file looks like this:
(ns myapp.server (:require ...))
(defonce server-state (atom {:nr 0}))
(defn handler [req]
(prn (swap! server-state update :nr inc))
{:body "Answer.\n"})
This works, every time the address localhost:3000 is visited the the atom is updated and the new version is printed to stdout inside the repl.
How can the atom been inspected at any time?
boot.user=> @myapp.server/server-state
yields an error. (...no such var...)
When trying the same thing from within an emacs cider nrepl connection, this previous attempt always shows up the initial value of the atom: {:n 0}
UPDATE
Here are the exact steps I do when using emacs/cider:
cd
projectdir- start
emacs
cider-jack-in
(boot (dev))
Ctrl+C+C
(in order to get a prompt again.)- Then Testing with
curl
: getting responses + inside emacs updated atom is logged:{:n 1}
..{:n 2}
.. - Then, in the repl:
(require 'myapp.server)
, takes a while:nil
. - finally:
@myapp.server/state
--> however:{:n 0}