<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Clojure Q&amp;A - Recent questions tagged agent</title>
<link>https://ask.clojure.org/index.php/tag/agent</link>
<description></description>
<item>
<title>Why does `await` fire off an `agent`'s watch?</title>
<link>https://ask.clojure.org/index.php/14357/why-does-await-fire-off-an-agent-s-watch</link>
<description>&lt;p&gt;I'm having trouble understand how &lt;code&gt;await&lt;/code&gt; works on agents.&lt;br&gt;
From the doc string reads&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Blocks the current thread (indefinitely!) until all actions dispatched&lt;br&gt;
thus far, from this thread or agent, to the agent(s) have occurred.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;So sounds like it should wait for any tasks running on a given agent or any work that agent has dispatched itself (say to other agents or threads). So if I  &lt;code&gt;send&lt;/code&gt; something then I can &lt;code&gt;await&lt;/code&gt; for it to finish. &lt;/p&gt;
&lt;p&gt;However, it seems like a &lt;code&gt;watch&lt;/code&gt; will also triggers for some reason...&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(def bond (agent nil))

(add-watch bond
           :test
           (fn [_,_,_,_]
             (println &quot;pew pew&quot;)))

(await bond)

;; the value of bond hasnt changed but it prints &quot;pew pew&quot; ..?

;; can be called an arbitrary number of times - keeps firing

(await bond)
(await bond)
(await bond)
(await bond)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;add-watch&lt;/code&gt; docs read&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Whenever the reference's state might have been changed, any registered watches will have their functions called.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;However here the agent's state hasn't changed and yet it's fired&lt;/p&gt;
&lt;p&gt;What's going on?&lt;/p&gt;
</description>
<category>Refs, agents, atoms</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14357/why-does-await-fire-off-an-agent-s-watch</guid>
<pubDate>Sat, 25 Jan 2025 04:40:53 +0000</pubDate>
</item>
<item>
<title>Is there a polished version of auto-agents?</title>
<link>https://ask.clojure.org/index.php/14318/is-there-a-polished-version-of-auto-agents</link>
<description>&lt;p&gt;I was reading Clojure in Action and thinking about agents. It seems that by hooking up agents with watches, update functions, and some simple locks, you could create a “reactive&quot; state management. So that when some value &lt;code&gt;a&lt;/code&gt; is updated then all dependent state values update themselves automatically and in parallel on separate threads. While those values are updating you are free to change other state values that aren't in the same dependency graph&lt;/p&gt;
&lt;p&gt;I wrote up a quick draft but then started to look around online (it felt like a bit too obvious of an extension to the agent model). I found some similar ideas back in ~2009 but the trail goes dry. Is there some reason this isn't used more widely? Or is this some modern library I'm missing?&lt;/p&gt;
&lt;p&gt;There was a &quot;cell&quot; implementation by Stuart Sierra called &lt;code&gt;auto-agents&lt;/code&gt; - though I can't find the code&lt;/p&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://groups.google.com/g/clojure/c/NY834N34QvA&quot;&gt;https://groups.google.com/g/clojure/c/NY834N34QvA&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I also found this complete implementation but it's also got no traction at all&lt;/p&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/apatil/lazy-agent&quot;&gt;https://github.com/apatil/lazy-agent&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Has this crystallized into a library somewhere? I'm thinking of writing my own implementation but I wanted a sanity check. I'm concerned maybe this idea was dropped for some reasons I've not considered&lt;/p&gt;
&lt;p&gt;(I'm aware there are things like Javelin, Odoyle and Missionary that can accomplish similar things.. but while they decouple code, they're way too complicated and some don't have a threading story)&lt;/p&gt;
&lt;p&gt;This is a copy of my question on Reddit:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://reddit.com/comments/1hklfyh/comment/m3gyyoq&quot;&gt;https://reddit.com/comments/1hklfyh/comment/m3gyyoq&lt;/a&gt;&lt;/p&gt;
</description>
<category>Refs, agents, atoms</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14318/is-there-a-polished-version-of-auto-agents</guid>
<pubDate>Thu, 26 Dec 2024 18:41:21 +0000</pubDate>
</item>
<item>
<title>How can I retrieve all older values of a PDS like atom/ref/agents ?</title>
<link>https://ask.clojure.org/index.php/11604/how-can-retrieve-all-older-values-of-pds-like-atom-ref-agents</link>
<description>&lt;p&gt;Based on my impression a PDS like clojure atom/refs/agents stores all new values in a tree like data-structure as they get changed over-time.&lt;/p&gt;
&lt;p&gt;Now, my questions are&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;In clojure, current values of an identity are could be accesses by defer/@ syntax, is it possible to access all the older values of an atom/ref/agent and print them ? If so, how ?&lt;/li&gt;
&lt;li&gt;If older values of an identity are NOT accessible, then what happens to them ? They are still in memory right ? If I cannot access them, what is the point of having a tree like structure ?&lt;/li&gt;
&lt;/ol&gt;
</description>
<category>Refs, agents, atoms</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/11604/how-can-retrieve-all-older-values-of-pds-like-atom-ref-agents</guid>
<pubDate>Sun, 27 Feb 2022 11:04:39 +0000</pubDate>
</item>
<item>
<title>How to known all the actions of an agent have been executed?</title>
<link>https://ask.clojure.org/index.php/10000/how-to-known-all-the-actions-of-an-agent-have-been-executed</link>
<description>&lt;p&gt;(def a (agent 0))&lt;/p&gt;
&lt;p&gt;(dotimes [_ 100]&lt;br&gt;
   (send-off a inc))&lt;/p&gt;
&lt;p&gt;How to determine the 100 actions have all been finished?&lt;/p&gt;
</description>
<category>Refs, agents, atoms</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10000/how-to-known-all-the-actions-of-an-agent-have-been-executed</guid>
<pubDate>Tue, 05 Jan 2021 03:33:56 +0000</pubDate>
</item>
</channel>
</rss>