From c8b128e33cef1e14d5f6727606baab01f2b11d4e Mon Sep 17 00:00:00 2001 From: anatoly Date: Tue, 27 Oct 2015 22:02:34 -0400 Subject: [PATCH] mount-state marker vs. session-id ts --- src/mount/mount.clj | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/mount/mount.clj b/src/mount/mount.clj index 59907ee..0bb42bc 100644 --- a/src/mount/mount.clj +++ b/src/mount/mount.clj @@ -5,7 +5,8 @@ (disable-reload!) -(defonce ^:private session-id (System/currentTimeMillis)) +;; (defonce ^:private session-id (System/currentTimeMillis)) +(defonce ^:private mount-state 42) (defonce ^:private state-seq (atom 0)) (defonce ^:private state-order (atom {})) @@ -29,7 +30,7 @@ (defmacro defstate [state & body] (let [[state [c cf d df]] (macro/name-with-attributes state body) {:keys [start stop]} (validate {c cf d df})] - (let [s-meta (-> {:session-id session-id + (let [s-meta (-> {:mount-state mount-state :order (make-state-seq state) :start `(fn [] (~@start)) :started? false} @@ -56,11 +57,15 @@ (throw (RuntimeException. (str "could not stop [" name "] due to") t))))) (alter-meta! var assoc :started? false))) +(defn mount-state? [var] + (= (-> var meta :mount-state) + mount-state)) + (defn find-all-states [] (->> (all-ns) (mapcat ns-interns) (map second) - (filter #(= (:session-id (meta %)) session-id)))) + (filter mount-state?))) ;; TODO: narrow down by {:mount {:include-ns ;; {:starts-with ["app.foo" "bar.baz"]