summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRich Hickey <richhickey@gmail.com>2009-01-26 17:03:42 +0000
committerRich Hickey <richhickey@gmail.com>2009-01-26 17:03:42 +0000
commitde15886acc72c98f2ce1284bb54147e35d8bbd59 (patch)
treeaf0cf1d839907a1ea78dc57bd6fd86f2a66bc624 /src
parentf0eef1192258f2908a860b151870e04a3a3ab5bc (diff)
added pcalls, pvalues
Diffstat (limited to 'src')
-rw-r--r--src/clj/clojure/core.clj13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj
index 8d3eef21..ca3acfac 100644
--- a/src/clj/clojure/core.clj
+++ b/src/clj/clojure/core.clj
@@ -3704,6 +3704,19 @@
"Returns true if coll implements Reversible"
[coll] (instance? clojure.lang.Reversible coll))
+(defn pcalls
+ "Executes the no-arg fns in parallel, returning a lazy sequence of
+ their values"
+ [& fns]
+ (let [futs (.invokeAll clojure.lang.Agent/pooledExecutor fns)]
+ (map #(.get %) futs)))
+
+(defmacro pvalues
+ "Returns a lazy sequence of the values of the exprs, which are
+ evaluated in parallel"
+ [& exprs]
+ `(pcalls ~@(map #(list `fn [] %) exprs)))
+
(defn pmap
"Like map, except f is applied in parallel. Semi-lazy in that the
parallel computation stays ahead of the consumption, but doesn't