aboutsummaryrefslogtreecommitdiff
path: root/modules/agent-utils/src/main/clojure
diff options
context:
space:
mode:
authorStuart Sierra <mail@stuartsierra.com>2010-08-07 16:41:53 -0400
committerStuart Sierra <mail@stuartsierra.com>2010-08-07 16:41:53 -0400
commita6a92b9b3d2bfd9a56e1e5e9cfba706d1aeeaae5 (patch)
treef1f3da9887dc2dc557df3282b0bcbd4d701ec593 /modules/agent-utils/src/main/clojure
parente7930c85290f77815cdb00a60604feedfa2d0194 (diff)
Split all namespaces into sub-modules.
* Examples and tests have not been copied over. * Clojure test/compile phases are commented out in parent POM. * May require installing parent POM before full build.
Diffstat (limited to 'modules/agent-utils/src/main/clojure')
-rw-r--r--modules/agent-utils/src/main/clojure/clojure/contrib/agent_utils.clj35
1 files changed, 35 insertions, 0 deletions
diff --git a/modules/agent-utils/src/main/clojure/clojure/contrib/agent_utils.clj b/modules/agent-utils/src/main/clojure/clojure/contrib/agent_utils.clj
new file mode 100644
index 00000000..1b7b2107
--- /dev/null
+++ b/modules/agent-utils/src/main/clojure/clojure/contrib/agent_utils.clj
@@ -0,0 +1,35 @@
+; Copyright (c) Christophe Grand, November 2008. All rights reserved.
+
+; The use and distribution terms for this software are covered by the
+; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
+; which can be found in the file epl-v10.html at the root of this
+; distribution.
+; By using this software in any fashion, you are agreeing to be bound by
+; the terms of this license.
+; You must not remove this notice, or any other, from this software.
+
+;; misc agent utilities
+
+;; note to other contrib members: feel free to add to this lib
+
+(ns
+ ^{:author "Christophe Grande",
+ :doc "Miscellaneous agent utilities
+ (note to other contrib members: feel free to add to this lib)",
+}
+ clojure.contrib.agent-utils)
+
+(defmacro capture-and-send
+ "Capture the current value of the specified vars and rebind
+ them on the agent thread before executing the action.
+
+ Example:
+ (capture-and-send [*out*] a f b c)"
+
+ [vars agent action & args]
+ (let [locals (map #(gensym (name %)) vars)]
+ `(let [~@(interleave locals vars)
+ action# (fn [& args#]
+ (binding [~@(interleave vars locals)]
+ (apply ~action args#)))]
+ (send ~agent action# ~@args))))