Skip to content

Instantly share code, notes, and snippets.

@lynaghk
Last active July 25, 2017 23:07
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 lynaghk/01aaa39bedcd2d37032dba3b68d9f94f to your computer and use it in GitHub Desktop.
Save lynaghk/01aaa39bedcd2d37032dba3b68d9f94f to your computer and use it in GitHub Desktop.
core.async
(let [start (.getTime (java.util.Date.))
c-inputs (async/chan)
c-outputs (async/chan)]
(async/onto-chan c-inputs (range 10))
(async/pipeline-async 1
c-outputs
(fn [x c-out]
(async/thread
(Thread/sleep 2000)
(async/put! c-out x)
(async/close! c-out)))
c-inputs)
(loop [res (<!! c-outputs)]
(if (nil? res)
(println (- (.getTime (java.util.Date.)) start) "done")
(do
(println (- (.getTime (java.util.Date.)) start) res)
(recur (<!! c-outputs))))))
;; Using [org.clojure/core.async "0.3.443"]
;; Output indicates that three async tasks are running at the same time, even though `pipeline-async` n = 1:
;;
;; 2004 0
;; 2004 1
;; 2004 2
;; 4005 3
;; 4005 4
;; 4006 5
;; 6007 6
;; 6009 7
;; 6009 8
;; 8009 9
;; 8010 done
@lynaghk
Copy link
Author

lynaghk commented Jul 25, 2017

Issue here: https://dev.clojure.org/jira/browse/ASYNC-163 Thanks hiredman in clojure slack channel for the pointer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment