summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRich Hickey <richhickey@gmail.com>2008-12-23 19:23:34 +0000
committerRich Hickey <richhickey@gmail.com>2008-12-23 19:23:34 +0000
commitc29ccf985770f751a41f7e5728938af0316b5dfe (patch)
tree83d8c0c52c943303f106ca0c1d364eb48c5ce5bf /src
parent7d603560e3a43ba8e787a38312319ff0d6139b54 (diff)
added release-pending-sends
Diffstat (limited to 'src')
-rw-r--r--src/clj/clojure/core.clj9
-rw-r--r--src/jvm/clojure/lang/Agent.java18
2 files changed, 22 insertions, 5 deletions
diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj
index 4cb7fd66..c6e81bad 100644
--- a/src/clj/clojure/core.clj
+++ b/src/clj/clojure/core.clj
@@ -1074,6 +1074,15 @@
[#^clojure.lang.Agent a f & args]
(. a (dispatch f args true)))
+(defn release-pending-sends
+ "Normally, actions sent directly or indirectly during another action
+ are held until the action completes (changes the agent's
+ state). This function can be used to dispatch any pending sent
+ actions immediately. This has no impact on actions sent during a
+ transaction, which are still held until commit. If no action is
+ occurring, does nothing. Returns the number of actions dispatched."
+ [] (clojure.lang.Agent/releasePendingSends))
+
(defn add-watch
"Experimental.
Adds a watcher to an agent. Whenever the agent runs an action, any
diff --git a/src/jvm/clojure/lang/Agent.java b/src/jvm/clojure/lang/Agent.java
index 55b97df8..e4500174 100644
--- a/src/jvm/clojure/lang/Agent.java
+++ b/src/jvm/clojure/lang/Agent.java
@@ -84,11 +84,7 @@ static class Action implements Runnable{
if(!hadError)
{
- for(ISeq s = nested.get().seq(); s != null; s = s.rest())
- {
- Action a = (Action) s.first();
- a.agent.enqueue(a);
- }
+ releasePendingSends();
}
boolean popped = false;
@@ -232,4 +228,16 @@ public Agent removeWatch(Object watcher) throws Exception{
return this;
}
+static public int releasePendingSends(){
+ IPersistentVector sends = nested.get();
+ if(sends == null)
+ return 0;
+ for(int i=0;i<sends.count();i++)
+ {
+ Action a = (Action) sends.valAt(i);
+ a.agent.enqueue(a);
+ }
+ nested.set(PersistentVector.EMPTY);
+ return sends.count();
+}
}