-
Notifications
You must be signed in to change notification settings - Fork 1
/
time.clj
37 lines (27 loc) · 988 Bytes
/
time.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
37
(ns active.clojure.logger.time
"Get current system time"
(:require [active.clojure.monad :as monad]
[active.clojure.record :refer [define-record-type]]))
(define-record-type ^{:doc "Get the system time in milliseconds"} GetMilliTime
(make-get-milli-time) get-milli-time? [])
(def get-milli-time (make-get-milli-time))
(defn get-milli-time!
[]
(System/currentTimeMillis))
(define-record-type ^{:doc "Get the elapsed time in milliseconds. Only useful for precise measurments of elapsed time."} GetElapsedTime
(make-get-elapsed-time) get-elapsed-time? [])
(def get-elapsed-time (make-get-elapsed-time))
(defn get-elapsed-time!
[]
(/ (double (System/nanoTime)) 1000000.0))
(defn run-time
[_run-any _env mstate m]
(cond
(get-milli-time? m)
[(get-milli-time!) mstate]
(get-elapsed-time? m)
[(get-elapsed-time!) mstate]
:else
monad/unknown-command))
(def monad-command-config
(monad/make-monad-command-config run-time {} {}))