-
Notifications
You must be signed in to change notification settings - Fork 0
/
timing.clj
36 lines (30 loc) · 934 Bytes
/
timing.clj
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
(ns manifold.lifecycle.timing
"Lifecycle wrapper for timing steps")
(defn initializer
[clock]
(fn [init]
(let [timestamp (clock)]
(-> {:timing {:created-at timestamp
:updated-at timestamp
:index 0
:output []}}
(merge init)))))
(defn augmenter
[clock]
(fn [context {:keys [id] :as step}]
(let [timestamp (clock)
timing (- timestamp (get-in context [:timing :updated-at]))]
(-> context
(update-in [:timing :index] inc)
(assoc-in [:timing :updated-at] timestamp)
(update-in [:timing :output] conj {:id id :timing timing})))))
(def wall-clock
"Default clock for timing"
#(System/currentTimeMillis))
(defn make
[clock]
{:initialize (initializer clock)
:augment (augmenter clock)})
(def milliseconds
"A timing helper at millisecond resolution"
(make wall-clock))