Created
March 16, 2025 03:06
-
-
Save shaunlebron/0889c21eabf648a88c4893caeecd197f to your computer and use it in GitHub Desktop.
setTimeout and setInterval in clojure (java)
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
(ns user | |
(:import (java.util.concurrent Executors TimeUnit))) | |
(defn set-timeout [^Callable f ^long ms] | |
(doto (Executors/newScheduledThreadPool 1) | |
(.schedule f ms TimeUnit/MILLISECONDS))) | |
(defn set-interval [^Callable f ^long ms] | |
(doto (Executors/newScheduledThreadPool 1) | |
(.scheduleAtFixedRate f 0 ms TimeUnit/MILLISECONDS))) | |
(comment | |
(def ses (set-timeout (fn [] (println "HI")) 1000)) | |
(def ses (set-interval (fn [] (println "HI")) 1000)) | |
(.shutdown ses) | |
(.shutdownNow ses)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment