notice however that it is just how we designed the state: i.e. :connected comes from the connect function and gets to live within the db state.
(!) The interesting bit here is the true runtime state of the database connection: if the connection gets closed at runtime due to, say, a network glitch, the (:connected db) will still return true.
Checking by the state name
running states
You can always check the state by its fully qualified name via (mount/running-states) which returns a set of all the states started by mount, although I find it only useful for debugging purposes:
It would depend on what / where this question needs to be answered. Here is why:
Tale of Modes
mount has two modes
clj
andcljc
.In the default,
clj
mode, the real instance of a started state is the state itself. For example:notice that after the start is called
a
becomes42
(i.e.java.util.Long
).Whereas in
cljc
mode all states are derefable even when started, which means the real instance (whether started or stopped) is hiding behind the@
:notice how
a
is still derefable even after it is started.Meaning of Started and Stopped
Let's say we have a database connection that we need to check the start/stop status for:
Until it's started it is "not going to be connected":
once it is started, it will be "connected":
notice however that it is just how we designed the
state
: i.e.:connected
comes from theconnect
function and gets to live within thedb
state.(!) The interesting bit here is the true runtime state of the database connection: if the connection gets closed at runtime due to, say, a network glitch, the
(:connected db)
will still returntrue
.Checking by the state name
running states
You can always check the state by its fully qualified name via
(mount/running-states)
which returns a set of all the states started by mount, although I find it only useful for debugging purposes:app graph
Or you can search in the graph by the state name (again, usually useful mostly for monitoring / debugging):
(mount/start) does it
But in practice, if
(mount/start)
is called all of the states will be started (unless there are errors in one of the start functions).Another interesting property of
cljc
mode, is that states can be started lazily:this worked without calling
(mount/start)
, since@
will start the state if it was not already started.