anyone think the docstring for https://clojure.github.io/core.async/#clojure.core.async/pipeline-async is inconsistent with the behaviour of:
(async/pipeline-async
10
(async/chan 100)
#(async/thread (async/>!! %2 %1) (println "put " %1 " once") (async/>!! %2 %1) (println "put " %1 " twice"))
(async/to-chan (range 10)))
docstring specifically says "result(s)" but my reading of the code (and those results) is that af can only reliably place 1 result
“af must close! the channel before returning”
?
there is at least one pending ticket related to the docs for this
ah! ok apparently I just didn't understand the code when I read it
because you're right, if I close the channels it works as intended.
https://github.com/clojure/core.async/blob/master/src/test/clojure/clojure/core/pipeline_test.clj might be helpful for patterns too
so it works, but it's not asynchronous anymore after the first value is put on the channel
(async/pipeline-async
10
(async/chan 100)
#(async/thread
(async/>!! %2 %1)
(println "put " %1 " once")
(Thread/sleep 1000)
(async/>!! %2 %1)
(println "put " %1 " twice")
(Thread/sleep 1000)
(async/>!! %2 %1)
(println "put " %1 " thrice")
(Thread/sleep 1000)
(async/close! %2))
(async/to-chan (range 10)))
=>
#object[clojure.core.async.impl.channels.ManyToManyChannel
0x1be4a99a
"clojure.core.async.impl.channels.ManyToManyChannel@1be4a99a"]
put put 0 once5
put 4 once
put 1 once
once
put 2 once
put put 6 9 once
once
put put put 8 3 once
once
7 once
put 0 twice
put 0 thrice
put 1 twice
put 1 thrice
put 2 twice
put 2 thrice
put 3 twice
put 3 thrice
put 4 twice
put 4 thrice
put 5 twice
put 5 thrice
put 6 twice
put 6 thrice
put 7 twice
put 7 thrice
put 8 twice
put 8 thrice
put 9 twice
put 9 thrice
or.. it's "asynchronous" but the channels and threads block each other in such a way that things can only happen in sequence
I suppose that's probably necessary for "Outputs will be returned in order relative to the inputs." it's surprising though
it’s necessary for ordering
indeed. I guess pipeline just isn't a great fit here