Skip to content

Instantly share code, notes, and snippets.

@maxweber
Created February 11, 2016 09:43
Show Gist options
  • Save maxweber/6d9d1a630884f0376487 to your computer and use it in GitHub Desktop.
Save maxweber/6d9d1a630884f0376487 to your computer and use it in GitHub Desktop.
(defn io-map
([number-of-threads f seq]
(let [executor (java.util.concurrent.Executors/newFixedThreadPool number-of-threads)
results (.invokeAll executor (map (fn [x] #(f x)) seq))
result (doall (map deref results))]
(.shutdown executor)
result))
([f seq] (io-map 50 f seq)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment