-
Notifications
You must be signed in to change notification settings - Fork 16
/
promesa.cljc
45 lines (43 loc) · 1.52 KB
/
promesa.cljc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
(ns juxt.clip.promesa
(:require
[promesa.core :as p]))
(defn exec
([q] (exec q (p/resolved {})))
([q init]
(reduce
(fn [*acc f]
(-> *acc
(p/then
(fn [acc]
(try
(f (fn [acc k v]
(-> (p/all [acc k v])
(p/then #(apply assoc %))
(p/catch
(fn [e]
(throw (ex-info "Failure while executing on system"
{:juxt.clip.core/type :thrown
:juxt.clip.core/system acc
:juxt.clip.core/unapplied-v v}
e))))))
acc)
(catch #?(:clj Throwable :cljs js/Error) t
(throw (ex-info "Failure while executing on system"
{:juxt.clip.core/type :thrown
:juxt.clip.core/system acc}
t))))))))
init
q)))
(comment
(def system2
{:foo {:start `(p/resolved 10)}
:bar {:start '(inc (clip/ref :foo))}})
(require '[juxt.clip.impl.core :as impl])
@(exec
(concat
(for [f [(impl/pre-starting-f system2)
(impl/starting-f system2)]
component (impl/component-chain system2)]
(f component))
(map impl/stopping-f (impl/reverse-component-chain system2))))
)