-
-
Save lynaghk/01aaa39bedcd2d37032dba3b68d9f94f to your computer and use it in GitHub Desktop.
core.async
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
(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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Issue here: https://dev.clojure.org/jira/browse/ASYNC-163 Thanks hiredman in clojure slack channel for the pointer.