This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-04-27
Channels
- # architecture (6)
- # beginners (36)
- # boot (4)
- # cider (74)
- # cljsrn (5)
- # clojure (87)
- # clojure-denver (2)
- # clojure-finland (2)
- # clojure-gamedev (5)
- # clojure-italy (10)
- # clojure-nl (1)
- # clojure-uk (45)
- # clojurescript (33)
- # code-reviews (5)
- # core-async (12)
- # cursive (17)
- # datascript (2)
- # datomic (71)
- # duct (4)
- # emacs (19)
- # figwheel (1)
- # fulcro (4)
- # garden (1)
- # hoplon (18)
- # jobs (5)
- # leiningen (2)
- # off-topic (73)
- # onyx (14)
- # overtone (2)
- # portkey (32)
- # re-frame (62)
- # reagent (46)
- # shadow-cljs (76)
- # spacemacs (2)
- # sql (14)
- # tools-deps (5)
- # yada (3)
Is there a good way of making a particular function run every n
seconds—regardless of how long it takes to execute the function? I know I can do (<! (timeout 1000))
, execute the function, then loop, but then it would get slowly out of sync as the function takes time to execute.
you could use https://docs.oracle.com/javase/7/docs/api/java/util/TimerTask.html or https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ScheduledExecutorService.html
I think this will work:
(let [t (timeout 1000)
(run-function...)
(<! t))
Thanks, @U064X3EF3 @U07TDTQNL, oh I hadn't thought about creating the timeout channel before using it. Would is still fall out of sync from the time it takes to create the timeout channel?
@U5JUDH2UE yes, and it will be out of sync because timeouts are only accurate to about 5-10ms. But really if you need better resolution than that, I don't know that core.async is the best tool
And by "resolution" mean that multiple calls to timeout
within a . 5-10ms window all get the same timeout channel
or you can create a thread, schedule a new thread tobe created in 1000 and execute your function
is there a chance the ioc machinery will be eventually available as a separate library ?
Rich has talked about the idea of moving a subset of it into core but I find it hard to imagine that bubbling to the top of the list any time soon