Skip to content

Instantly share code, notes, and snippets.

@ktsujister
Created October 29, 2014 09:39
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 ktsujister/67b68c059e8b6b540cf3 to your computer and use it in GitHub Desktop.
Save ktsujister/67b68c059e8b6b540cf3 to your computer and use it in GitHub Desktop.
;;; lazy-seq based flow
(defn proc-a [id]
;; 処理A
url)
(defn proc-b [url]
;; 処理B
json
)
(defn proc-c [json]
;; 処理C
)
(->> (io/reader "ids.txt")
line-seq
(map proc-a)
(map proc-b)
(map proc-c))
;;; core.async + transducer based flow
(let [in-ch (->> (io/reader "ids.txt")
line-seq
a/to-chan)
xf (comp (map proc-a)
(map proc-b)
(map proc-c))
out-ch (chan)
worker-count 4]
(a/pipeline worker-count out-ch xf in-ch))
;;; core.async + transducer based flow
(let [in-ch (->> (io/reader "ids.txt")
line-seq
a/to-chan)
a-xf (map proc-a)
b-xf (map proc-b)
c-xf (map proc-c)
a-worker-count 8
a-out-ch (chan a-worker-count)
b-worker-count 4
b-out-ch (chan b-worker-count)
c-worker-count 2
c-out-ch (chan c-worker-count)]
(a/pipeline a-worker-count a-out-ch a-xf in-ch)
(a/pipeline b-worker-count b-out-ch b-xf a-out-ch)
(a/pipeline-blocking c-worker-count c-out-ch c-xf b-out-ch)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment