How should I suppose to put a value on a manifold stream without blocking ?
@lxsameer stream/put!
doesn't block - it returns a Deferred
So let me rephrase my question, How can I put a value in an stream in a parallel fashion. Right now even if I consume from the stream and block in the consumer function it still runs my code in a thread
so it blocks
that thread
don't block in the consumer function - use deferred/zip
to collate responses once you have put all values on to the stream
oops, i think i may have misunderstood what you wrote
what's blocking ?
@mccraigmccraig let me show some code
@mccraigmccraig check this out http://dpaste.com/19CC303
the output of this code would be number 1-199 in order and all of them executed on the same thread.
In my understanding, the consume-async function should get a value from stream and apply the given fn to that value asynchronously
so if something is blocking the current thread (call to sleep) it should run fn in another thread in the threadpool
and if that's the case i should be able to see that some of those function runs in a different thread and the i should be able to see number printing on the out out of order ( with random sleep ofcourse )
but it's not happening
if you want I can provide the output as well
hmm. i dunno - i would have expected that as well... things to look at - what happens if you use put-all!
with a range instead of put!
... what happens if you don't used a fixed-thread-executor
?
I have to test the put-all!
but without the executor the result would be the same
can you paste the output as well...
@mccraigmccraig result is the same with put-all!
as well
reduced the number to 100
looking at the docs for consume-async
https://github.com/ztellman/manifold/blob/master/src/manifold/stream.clj#L483 this result seems in line with expectations... i don't think i've ever used consume-async
hmmmm , very weird. It would be a good candidate for zack to include it in the naming chapter of elements of clojure