Add pmapallv utility function
This commit is contained in:
parent
6eccd21ece
commit
0aa8af7993
@ -85,3 +85,22 @@
|
|||||||
zip/path
|
zip/path
|
||||||
count
|
count
|
||||||
(max height))))))
|
(max height))))))
|
||||||
|
|
||||||
|
(defn pmapallv
|
||||||
|
"A utility for concurrent execution of a function on items in a collection.
|
||||||
|
In single-thread-mode this acts like mapv. Otherwise it acts like pmap but:
|
||||||
|
1) coll should be finite, 2) the returned sequence will not be lazy, and will
|
||||||
|
in fact be a vector, 3) calls to f may occur in any order, to maximize
|
||||||
|
multicore processor utilization, and 4) takes only one coll so far."
|
||||||
|
[f coll args]
|
||||||
|
#?(:clj (vec (if (:single-thread-mode args)
|
||||||
|
(doall (map f coll))
|
||||||
|
(let [agents (map #(agent % :error-handler
|
||||||
|
(fn [agnt except]
|
||||||
|
(clojure.repl/pst except 1000)
|
||||||
|
(System/exit 0)))
|
||||||
|
coll)]
|
||||||
|
(dorun (map #(send % f) agents))
|
||||||
|
(apply await agents)
|
||||||
|
(doall (map deref agents)))))
|
||||||
|
:cljs (mapv f coll)))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user