Last active
December 21, 2015 03:08
-
-
Save gerritjvv/6239976 to your computer and use it in GitHub Desktop.
Clojure core.async schedule fixed delay actions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;Print "Hi" every 2 seconds: | |
(defn t [] | |
(go (loop [] (<! (timeout 2000)) (prn "hi") (recur)))) | |
;or as a macro | |
(defmacro fixdelay [ ms & body] | |
`(go (loop [] (<! (timeout ~ms)) ~@body (recur)))) | |
;now we can do | |
(fixdelay 2000 (prn "hi")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment