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:
parent
45934f0780
commit
c0791c6f4a
3 changed files with 16 additions and 4 deletions
|
|
@ -155,9 +155,9 @@ dev=> (mount/stop)
|
||||||
dev=> (mount/start)
|
dev=> (mount/start)
|
||||||
```
|
```
|
||||||
|
|
||||||
This can be easily hooked up to [tools.namespace](https://github.com/clojure/tools.namespace), to make the whole
|
While it is not always necessary, mount lificycle can be easily hooked up to [tools.namespace](https://github.com/clojure/tools.namespace),
|
||||||
application reloadable with refreshing the app namespaces. Here is a [dev.clj](https://github.com/tolitius/mount/blob/master/dev/dev.clj) as
|
to make the whole application reloadable with refreshing the app namespaces.
|
||||||
an example, that sums up to:
|
Here is a [dev.clj](https://github.com/tolitius/mount/blob/master/dev/dev.clj) as an example, that sums up to:
|
||||||
|
|
||||||
```clojure
|
```clojure
|
||||||
(defn go []
|
(defn go []
|
||||||
|
|
|
||||||
|
|
@ -54,9 +54,9 @@
|
||||||
(when stop
|
(when stop
|
||||||
(try
|
(try
|
||||||
(stop)
|
(stop)
|
||||||
(intern ns (symbol name) (NotStartedState. name))
|
|
||||||
(catch Throwable t
|
(catch Throwable t
|
||||||
(throw (RuntimeException. (str "could not stop [" name "] due to") 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)))
|
(alter-meta! var assoc :started? false)))
|
||||||
|
|
||||||
;;TODO args might need more thinking
|
;;TODO args might need more thinking
|
||||||
|
|
|
||||||
|
|
@ -25,4 +25,16 @@
|
||||||
(is (map? app-config))
|
(is (map? app-config))
|
||||||
(is (instance? clojure.tools.nrepl.server.Server nrepl))
|
(is (instance? clojure.tools.nrepl.server.Server nrepl))
|
||||||
(is (instance? datomic.peer.LocalConnection conn))
|
(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))))
|
(mount/stop))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue