Created
August 28, 2019 08:30
-
-
Save joinr/c1fa20d6f7f2db6c534e0c4c688468e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns par | |
(:require [clojure.core.async :as a])) | |
(def my-data-log (atom [])) | |
(defn fetch-data! [n] | |
(Thread/sleep 1e3) | |
(swap! my-data-log conj (str "Fetched record: " n)) | |
n) | |
(defn work! [n] | |
(let [output-chan (a/chan)] | |
(a/pipeline-blocking n | |
output-chan | |
(map fetch-data!) | |
(a/to-chan (range 99))) | |
(a/<!! (a/into [] output-chan)))) | |
;;par> (time (count (work! 100))) | |
;;"Elapsed time: 1013.54152 msecs" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment