#69: stop accepts collections of states

vs. an implicit all and varargs
This commit is contained in:
anatoly 2016-11-28 11:30:38 -05:00
parent e2ef7bba55
commit 62cb9dd516
2 changed files with 23 additions and 7 deletions

View file

@ -244,7 +244,7 @@
(defn start [& states]
(let [fs (-> states first)]
(if (coll? fs)
(if-not (empty? fs) ;; (mount/start) vs. (mount/start #{}) vs. (mount/start #{1 2 3})
(if-not (empty? fs) ;; (mount/start) vs. (mount/start #{}) vs. (mount/start #{1 2 3})
(apply start fs)
{:started #{}})
(let [states (or (seq states)
@ -252,11 +252,17 @@
{:started (bring states up <)}))))
(defn stop [& states]
(let [states (or states (find-all-states))
_ (dorun (map unsub states)) ;; unmark substitutions marked by "start-with"
stopped (bring states down >)]
(dorun (map rollback! states)) ;; restore to origin from "start-with"
{:stopped stopped}))
(let [fs (-> states first)]
(if (coll? fs)
(if-not (empty? fs) ;; (mount/start) vs. (mount/start #{}) vs. (mount/start #{1 2 3})
(apply stop fs)
{:stopped #{}})
(let [states (or (seq states)
(find-all-states))
_ (dorun (map unsub states)) ;; unmark substitutions marked by "start-with"
stopped (bring states down >)]
(dorun (map rollback! states)) ;; restore to origin from "start-with"
{:stopped stopped}))))
;; composable set of states

View file

@ -167,4 +167,14 @@
(let [scope #{}]
(is (= {:started #{}} (-> (only scope)
mount/start)))
(mount/stop)))))
(mount/stop)))
(testing "should not stop anything on empty seq of states"
(let [scope #{}]
(mount/start)
(is (instance? datomic.peer.LocalConnection (dval conn)))
(is (= {:stopped #{}} (-> (only scope)
mount/stop)))
(is (instance? datomic.peer.LocalConnection (dval conn)))
(mount/stop)
(is (instance? mount.core.NotStartedState (dval conn)))))))