Skip to content

Commit

Permalink
WIP: Make possible to supply custom chains
Browse files Browse the repository at this point in the history
Fix #3
Relates to #2
  • Loading branch information
SevereOverfl0w committed Oct 10, 2021
1 parent 75506eb commit 88fd8c7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
37 changes: 27 additions & 10 deletions src/juxt/clip/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,29 @@
of requiring a code form, in addition the anaphoric variable `this` is
available to refer to the started component."
[system-config]
(let [{:keys [components executor]
:or {executor impl/exec-queue}} system-config
(let [{:keys [components executor chains]
:or {executor impl/exec-queue
chains {:start
(fn [component-chain]
(for [component component-chain
f [(impl/pre-starting-f components)
(impl/starting-f components)
(impl/post-starting-f components)]]
(f component)))}}} system-config
[_ component-chain] (safely-derive-parts components [])]
(executor
(for [component component-chain
f [(impl/pre-starting-f components)
(impl/starting-f components)
(impl/post-starting-f components)]]
(f component)))))
((get chains :start) component-chain))))

(comment
(let [components {:a '{:pre-start (println "pre" 1)
:start (inc 2)
:post-start (println "iam" this)}}]
(start
{:components components
:chains {:start [#_(impl/pre-starting-f components)
(impl/starting-f components)
(impl/post-starting-f components)]}}))
)

(defn stop
"Takes a system config to stop.
Expand All @@ -51,13 +65,16 @@
the target is AutoClosable then .close will be called on it, otherwise
nothing."
[system-config running-system]
(let [{:keys [components executor]
:or {executor impl/exec-queue}} system-config
(let [{:keys [components executor chains]
:or {executor impl/exec-queue
chains {:stop
(fn [component-chain]
(map impl/stopping-f component-chain))}}} system-config
[_ component-chain] (safely-derive-parts
(select-keys components (keys running-system))
())]
(executor
(map impl/stopping-f component-chain)
((get chains :stop) component-chain)
running-system)))

(comment
Expand Down
10 changes: 10 additions & 0 deletions src/juxt/clip/edn.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@
executor
(requiring-resolve executor)))

(defmethod edn->clj :chains
[_k chains]
(reduce-kv
(fn [chains method chain]
(if (symbol? chain)
(assoc chains method (requiring-resolve chain))
chains))
chains
chains))

(defn analyze
[system-config]
(reduce-kv
Expand Down

0 comments on commit 88fd8c7

Please sign in to comment.