init commit
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
(ns timer
|
||||
"Erlang :timer module — timer utilities.
|
||||
|
||||
In CljElixir: (timer/sleep 1000), (timer/send-after 5000 pid :msg), etc.
|
||||
Note: for most uses, Process/send-after is preferred in Elixir.")
|
||||
|
||||
(defn sleep
|
||||
"Suspends the calling process for `time` milliseconds.
|
||||
(timer/sleep 1000) ;=> :ok (sleeps 1 second)
|
||||
(timer/sleep :infinity) ;=> blocks forever"
|
||||
[time])
|
||||
|
||||
(defn send-after
|
||||
"Sends `message` to `pid` after `time` milliseconds. Returns {:ok tref}.
|
||||
(timer/send-after 5000 (Process/self) :timeout)"
|
||||
([time pid message])
|
||||
([time message]))
|
||||
|
||||
(defn send-interval
|
||||
"Sends `message` to `pid` every `time` milliseconds. Returns {:ok tref}.
|
||||
(timer/send-interval 1000 (Process/self) :tick)"
|
||||
([time pid message])
|
||||
([time message]))
|
||||
|
||||
(defn apply-after
|
||||
"Applies `module:function(args)` after `time` milliseconds.
|
||||
(timer/apply-after 5000 IO :puts [\"delayed\"])"
|
||||
[time module function args])
|
||||
|
||||
(defn apply-interval
|
||||
"Applies `module:function(args)` every `time` milliseconds."
|
||||
[time module function args])
|
||||
|
||||
(defn apply-repeatedly
|
||||
"Applies `module:function(args)` repeatedly with `time` delay after each."
|
||||
[time module function args])
|
||||
|
||||
(defn cancel
|
||||
"Cancels a timer.
|
||||
(timer/cancel tref) ;=> {:ok :cancel}"
|
||||
[tref])
|
||||
|
||||
(defn tc
|
||||
"Times the execution of a function. Returns {time result} in microseconds.
|
||||
(timer/tc (fn [] (fib 30))) ;=> {12345 832040}
|
||||
(timer/tc Enum :sort [[3 1 2]]) ;=> {microsecs [1 2 3]}"
|
||||
([fun])
|
||||
([fun args])
|
||||
([module function args]))
|
||||
|
||||
(defn now-diff
|
||||
"Returns time difference in microseconds between two erlang:now() tuples."
|
||||
[t2 t1])
|
||||
|
||||
(defn seconds
|
||||
"Converts seconds to milliseconds.
|
||||
(timer/seconds 5) ;=> 5000"
|
||||
[secs])
|
||||
|
||||
(defn minutes
|
||||
"Converts minutes to milliseconds.
|
||||
(timer/minutes 5) ;=> 300000"
|
||||
[mins])
|
||||
|
||||
(defn hours
|
||||
"Converts hours to milliseconds.
|
||||
(timer/hours 1) ;=> 3600000"
|
||||
[hours])
|
||||
|
||||
(defn hms
|
||||
"Converts hours, minutes, seconds to milliseconds.
|
||||
(timer/hms 1 30 0) ;=> 5400000"
|
||||
[hours minutes seconds])
|
||||
Reference in New Issue
Block a user