Forked from anonymous/schedule_at_fixed_rate.clj
Last active
December 20, 2015 01:19
-
-
Save mwmitchell/6048627 to your computer and use it in GitHub Desktop.
This file contains 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
(import '(java.util.concurrent Executors TimeUnit)) | |
(defn schedule-at-fixed-rate [se f init-delay period] | |
(.scheduleAtFixedRate | |
se | |
(fn [] (try (f) (catch Throwable e (.printStackTrace e)))) | |
init-delay | |
period | |
TimeUnit/SECONDS)) | |
(defn cancel [se] | |
(.cancel se true)) | |
(def s (Executors/newSingleThreadScheduledExecutor)) | |
(def r (schedule-at-fixed-rate s #(prn "HI!") 5 5)) | |
;; wait... | |
(Thread/sleep 10000) | |
(cancel r) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment