Skip to content

Commit de15886

Browse files
committed
added pcalls, pvalues
1 parent f0eef11 commit de15886

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/clj/clojure/core.clj

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3704,6 +3704,19 @@
37043704
"Returns true if coll implements Reversible"
37053705
[coll] (instance? clojure.lang.Reversible coll))
37063706

3707+
(defn pcalls
3708+
"Executes the no-arg fns in parallel, returning a lazy sequence of
3709+
their values"
3710+
[& fns]
3711+
(let [futs (.invokeAll clojure.lang.Agent/pooledExecutor fns)]
3712+
(map #(.get %) futs)))
3713+
3714+
(defmacro pvalues
3715+
"Returns a lazy sequence of the values of the exprs, which are
3716+
evaluated in parallel"
3717+
[& exprs]
3718+
`(pcalls ~@(map #(list `fn [] %) exprs)))
3719+
37073720
(defn pmap
37083721
"Like map, except f is applied in parallel. Semi-lazy in that the
37093722
parallel computation stays ahead of the consumption, but doesn't

0 commit comments

Comments
 (0)