Fork me on GitHub
#mount
<
2023-03-13
>
pez08:03:58

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.)

tolitius20:03:51

@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

tolitius20:03:33

* 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)

pez21:03:40

@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. 😃

metal 2
tolitius21:03:02

it’s always good to know 🙂