Skip to content

Instantly share code, notes, and snippets.

@gerritjvv
Last active December 21, 2015 03:08
Show Gist options
  • Save gerritjvv/6239976 to your computer and use it in GitHub Desktop.
Save gerritjvv/6239976 to your computer and use it in GitHub Desktop.
Clojure core.async schedule fixed delay actions
;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