Skip to content

Instantly share code, notes, and snippets.

@pbaille
Last active December 27, 2016 17:13
Show Gist options
  • Select an option

  • Save pbaille/1f06c116b33172937eb1cf033f44b03a to your computer and use it in GitHub Desktop.

Select an option

Save pbaille/1f06c116b33172937eb1cf033f44b03a to your computer and use it in GitHub Desktop.
(defn set-timeout [f millis]
(let [running (atom true)]
(future
(while @running
(f)
(Thread/sleep millis)))
#(reset! running nil)))
;; start an interval, the stop function is returned and bound to stop-interval var
(def stop-interval (set-interval #(println "yop") 1000))
;; call it to stop it
(stop-interval)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment