【发布时间】:2016-01-24 23:22:32
【问题描述】:
我想每 10 秒执行一次函数。怎么做最简单的方法?在 core.async 中,有一个超时功能,它最多会等待那个时间,而我想要的是至少等待那个时间。
【问题讨论】:
标签: clojure core.async
我想每 10 秒执行一次函数。怎么做最简单的方法?在 core.async 中,有一个超时功能,它最多会等待那个时间,而我想要的是至少等待那个时间。
【问题讨论】:
标签: clojure core.async
at-at 是我的最爱。以下示例是从网页中复制的:
(use 'overtone.at-at)
(def my-pool (mk-pool))
(at (+ 1000 (now)) #(println "hello from the past!") my-pool)
如果您一般使用 core.async,chime 也很棒。 同样,取自他们的例子:
(: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)))))
【讨论】: