Josue, take a look at java Timers
https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Timer.html
There is also many ways to do that with clojure: using future, agents, or core.async.
Put this into the clojure.core will bring an unnecessary complexity and cost of maintenance.
There is also some design choices, like, it will run on a thread pool? it will wait the task to terminate to start to count the timeout? it can be blocking?
Depending on which set of choices that you pick, it would make harder to port this function to others (future) platforms: javascript do not support blocking, arduino do not have system clock...
So feel free to create your our josue.timer
API or using some already existing
Here a code using java timers:
(let [every-5-sec (java.time.Duration/parse "PT5S")
ok-task (proxy [java.util.TimerTask] []
(run []
(prn :ok)))
;; save this return for later
timer-task (doto (java.util.Timer.)
(.schedule ok-task
(.toMillis every-5-sec)
(.toMillis every-5-sec)))]
#_(.cancel ok-task)
#_(.cancel timer-task)
timer-task)