NotStartedState for states without :stop

In case a state does not have a :stop function, mount would (!) assume that
nothing needs to be cleaned on stop and will intern convert this state
to mount.NotStartedState on (mount/stop)
This commit is contained in:
anatoly 2015-11-16 09:07:55 -05:00
parent 45934f0780
commit c0791c6f4a
3 changed files with 16 additions and 4 deletions

View file

@ -155,9 +155,9 @@ dev=> (mount/stop)
dev=> (mount/start)
```
This can be easily hooked up to [tools.namespace](https://github.com/clojure/tools.namespace), to make the whole
application reloadable with refreshing the app namespaces. Here is a [dev.clj](https://github.com/tolitius/mount/blob/master/dev/dev.clj) as
an example, that sums up to:
While it is not always necessary, mount lificycle can be easily hooked up to [tools.namespace](https://github.com/clojure/tools.namespace),
to make the whole application reloadable with refreshing the app namespaces.
Here is a [dev.clj](https://github.com/tolitius/mount/blob/master/dev/dev.clj) as an example, that sums up to:
```clojure
(defn go []

View file

@ -54,9 +54,9 @@
(when stop
(try
(stop)
(intern ns (symbol name) (NotStartedState. name))
(catch Throwable t
(throw (RuntimeException. (str "could not stop [" name "] due to") t)))))
(intern ns (symbol name) (NotStartedState. name)) ;; (!) if a state does not have :stop when _should_ this might leak
(alter-meta! var assoc :started? false)))
;;TODO args might need more thinking

View file

@ -25,4 +25,16 @@
(is (map? app-config))
(is (instance? clojure.tools.nrepl.server.Server nrepl))
(is (instance? datomic.peer.LocalConnection conn))
(is (= test-conn 42))
(is (vector? test-nrepl))
(mount/stop)))
(testing "should start-without normally after start-with"
(let [_ (m/start-without #'check.start-with-test/test-conn
#'check.start-with-test/test-nrepl)]
(is (map? app-config))
(is (instance? clojure.tools.nrepl.server.Server nrepl))
(is (instance? datomic.peer.LocalConnection conn))
(is (instance? mount.NotStartedState test-conn))
(is (instance? mount.NotStartedState test-nrepl))
(mount/stop))))