Hello! Is mount/start idempotent? I start the system as part of connecting to the repl. When reconnecting the repl I want to avoid starting the app, but I don't really know if it is an initial connect or a reconnect. I could make do with some way to tell if the system is running, but I don't immediately see a way to do that. (I'm a complete mount noob.)
@pez
> I could make do with some way to tell if the system is running
you can use (mount/running-states) to see what is currently running:
dev=> (defstate db-connection :start (println "connecting")
:stop (println "disconnecting..."))
#'dev/db-connection
dev=> (mount/running-states)
#{}
dev=> (mount/start #'dev/db-connection)
connecting
{:started ["#'dev/db-connection"]}
dev=> (mount/running-states)
#{"#'dev/db-connection"}
> When reconnecting the repl I want to avoid starting the app
if the states are already started, mount wonโt be starting them again
dev=> (defstate db-connection :start (println "connecting")
:stop (println "disconnecting..."))
#'dev/db-connection
dev=> (mount/start #'dev/db-connection)
connecting
{:started ["#'dev/db-connection"]}
dev=> (mount/start #'dev/db-connection)
{:started []} ;; was not started again, since it is already started
* not sure if needed in this case, but just another piece of intel
if you recompile a namespace that contains defstate, mount would restart it
but, it could be optional by using :on-reload [value] meta (https://github.com/tolitius/mount#recompiling-namespaces-with-running-states)
@tolitius thanks! I was holding it wrong. Indeed checking for running states tells me what I need to know. And, it doesn't even seem like I need to know. ๐
itโs always good to know ๐