3

I want to execution a function every 10 seconds. How to do it the simplest way? In core.async, there is a timeout function which will at MOST wait that time, and what I want is to wait at LEAST that time.

Daniel Wu
  • 5,853
  • 12
  • 42
  • 93
  • 3
    Possible duplicate of [Periodically calling a function in Clojure](http://stackoverflow.com/questions/21404130/periodically-calling-a-function-in-clojure) – Shlomi Jan 25 '16 at 00:31

1 Answers1

4

at-at is my favorite. Example below is copied from the webpage:

(use 'overtone.at-at)
(def my-pool (mk-pool))
(at (+ 1000 (now)) #(println "hello from the past!") my-pool)

If you use core.async in general, chime is great too. Again, taken from their examples:

(:require [chime :refer [chime-ch]]
          [clj-time.core :as t]
          [clojure.core.async :as a :refer [<! go-loop]])

    (let [chimes (chime-ch [(-> 2 t/secs t/from-now)
                        (-> 3 t/secs t/from-now)])]
    (a/<!! (go-loop []
           (when-let [msg (<! chimes)]
             (prn "Chiming at:" msg)
             (recur)))))
Nicolas Modrzyk
  • 13,961
  • 2
  • 36
  • 40