开发者

Clojure refs and add-watch

Say I have a ref state which gets updated every 30 seconds and a fn I want to attach开发者_StackOverflow中文版 to it that may take longer to complete. Say at time 0 ref is updated and fn called at time 30 ref is again updated but fn is still running. Do I get two copies of the same function running or does it just skip and execute at time 60 assuming fn returns by then?

EDIT: I am trying to change the state of the ref. It is updated somewhere else I am just trying to use it as a trigger to do some control calculations.


if you use a ref the two functions would run in parallel and compete for the right to produce the next state of the ref with the loser having to run again.

This is one of the differences between refs and agents. agents run sequentially because they have a queue of functions waiting to run on them.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜