Hello All,
I am learning mount library in Clojure GitHub - tolitius/mount: managing Clojure and ClojureScript app state since (reset) . This is my code:
(ns mount-example.foo
(:require [mount.core :refer [defstate start stop]]))
;;=> nil
(defstate a
:start 42
:stop (println "Configuration cleared."))
;;=> #'mount-example.foo/a
(start)
;;=> Execution error (ClassCastException) at mount-example.core/eval491$fn (core.clj:20).
;; class clojure.lang.PersistentArrayMap cannot be cast to class java.util.concurrent.Future (clojure.lang.PersistentArrayMap is in unnamed module of loader 'app'; java.util.concurrent.Future is in module java.base of loader 'bootstrap')
;;
(stop)
I am not sure why I am getting the error above. Would be great if someone throws light upon it.
Thanks in advance.
Cannot reproduce it.
What version of Mount are you using? What’s the full stack trace of that exception? Are you sure there’s no some (defstate something-else) that fails?
Some words of caution about Mount in general:
- It relies on a global state, so you cannot e.g. have concurrent tests that require different mocks. Or tests that can be run in isolation in an idempotent way, at least not without some kind of manual “reference counting” where you call
(stop) on a particular state only when nothing else uses it anymore
- It doesn’t track dependencies between states, so you cannot
(start) some particular subset of all states without painstakingly tracking which states are also required
1 Like
When I copied the same code to another project and tried:
(ns mount-2.foo
(:require [mount.core :refer [defstate start stop]]))
;;=> nil
(defstate a
:start 42
:stop (println "Configuration cleared."))
;;=> #'mount-2.foo/a
a
;;=> #object[mount.core.NotStartedState 0x1c6cda3a "'#'mount-2.foo/a' is not started (to start all the states call mount/start)"]
(start)
;;=> {:started ["#'mount-2.foo/a"]}
a
;;=> 42
(stop)
;;=> {:stopped ["#'mount-2.foo/a"]}
a
;;=> #object[mount.core.NotStartedState 0x544f1271 "'#'mount-2.foo/a' is not started (to start all the states call mount/start)"]
It worked!
Now my question is, is there any local directory that mount uses to store stuff? My idea is to delete it, thus solving my issue.
I am using mount 0.1.23, this is my project.clj for the code that works now:
(defproject mount_2 "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
:url "https://www.eclipse.org/legal/epl-2.0/"}
:dependencies [[org.clojure/clojure "1.12.0"]
[mount "0.1.23"]]
:repl-options {:init-ns mount-2.core})
Mount doesn’t store anything anywhere. Maybe you have another namespace that gets loaded, maybe maybe else is happening. The only kind of relevant “cache” would be the classes directory if you used AOT compilation, but that should be used only if your sources are older than the cache, which should never happen unless your FS is messed up or your clock was changed or something else altered file modification time.
That error that you saw doesn’t indicate where exactly it happened - that’s why I asked about the full stack trace.