gpt4 book ai didi

clojure - 在 clojure 中定期运行任务的最简单方法是什么

转载 作者:行者123 更新时间:2023-12-01 12:30:08 26 4
gpt4 key购买 nike

我想每 10 秒执行一个函数。怎么做最简单?在 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)))))

关于clojure - 在 clojure 中定期运行任务的最简单方法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34982853/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com