Fork me on GitHub
Garrett Hopper03:04:09

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.


I think this will work:

(let [t (timeout 1000)
   (<! t))

Garrett Hopper13:04:08

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


new threads ?


or you can create a thread, schedule a new thread tobe created in 1000 and execute your function


but in general i think it would be better to use a proper scheduler


is there a chance the ioc machinery will be eventually available as a separate library ?

Alex Miller (Clojure team)11:04:21

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


glad to hear there's interest to move in that direction anyways