Fork me on GitHub
#mount
<
2016-07-21
>
timgilbert18:07:31

Hey, I have a slightly hypothetical question: I'm writing some shared library code, and in the ideal case I want it to work either with or without mount. Is there an easy way from my code determine if it's running inside mount? (Eg, whether (mount/start) has been called or not)

tolitius18:07:56

@timgilbert: will this work for you?

dev=> (mount/running-states)
nil

dev=> (mount/start)
...
{:started ["#'app.conf/config" "#'app.db/conn" "#'app.www/nyse-app" "#'app.example/nrepl"]}
dev=>

dev=> (mount/running-states)
("#'app.conf/config" "#'app.db/conn" "#'app.www/nyse-app" "#'app.example/nrepl")

dev=> (mount/stop "#'app.db/conn")
INFO  app.db - disconnecting from  datomic:
{:stopped ["#'app.db/conn"]}

dev=> (mount/running-states)
("#'app.conf/config" "#'app.www/nyse-app" "#'app.example/nrepl")

tolitius18:07:36

if yes, I put in in 0.1.11-SNAPSHOT

timgilbert18:07:39

Oh, that's great, thanks!

timgilbert19:07:13

I'll mess around with it and let you know. I'm still in the hammock phase of development right now

tolitius19:07:13

sure, let me know. I think running-states is good to have regardless, so thanks for bringing it up. you could also get it via graph, e.g.:

dev=> (require '[mount.tools.graph :as graph])
nil
dev=> (map :name (filter (comp :started :status) (graph/states-with-deps)))
()

dev=> (mount/start)
...
{:started ["#'app.conf/config" "#'app.db/conn" "#'app.www/nyse-app" "#'app.example/nrepl"]}

dev=> (map :name (filter (comp :started :status) (graph/states-with-deps)))
("#'app.conf/config" "#'app.db/conn" "#'app.www/nyse-app" "#'app.example/nrepl")

tolitius19:07:26

but (running-states) is a bit simpler