Skip to content

Instantly share code, notes, and snippets.

@joinr
Created August 28, 2019 08:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joinr/c1fa20d6f7f2db6c534e0c4c688468e4 to your computer and use it in GitHub Desktop.
Save joinr/c1fa20d6f7f2db6c534e0c4c688468e4 to your computer and use it in GitHub Desktop.
(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