Fork me on GitHub
#aleph
<
2018-06-04
>
lxsameer12:06:45

How should I suppose to put a value on a manifold stream without blocking ?

mccraigmccraig13:06:14

@lxsameer stream/put! doesn't block - it returns a Deferred

lxsameer13:06:48

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

lxsameer13:06:01

so it blocks

lxsameer13:06:11

that thread

mccraigmccraig13:06:49

don't block in the consumer function - use deferred/zip to collate responses once you have put all values on to the stream

mccraigmccraig13:06:17

oops, i think i may have misunderstood what you wrote

mccraigmccraig13:06:37

what's blocking ?

lxsameer14:06:47

@mccraigmccraig let me show some code

lxsameer14:06:34

the output of this code would be number 1-199 in order and all of them executed on the same thread.

lxsameer14:06:54

In my understanding, the consume-async function should get a value from stream and apply the given fn to that value asynchronously

lxsameer14:06:28

so if something is blocking the current thread (call to sleep) it should run fn in another thread in the threadpool

lxsameer14:06:32

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 )

lxsameer14:06:42

but it's not happening

lxsameer14:06:59

if you want I can provide the output as well

mccraigmccraig14:06:38

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 ?

lxsameer14:06:32

I have to test the put-all! but without the executor the result would be the same

mccraigmccraig14:06:58

can you paste the output as well...

lxsameer14:06:59

@mccraigmccraig result is the same with put-all! as well

lxsameer14:06:42

reduced the number to 100

mccraigmccraig14:06:33

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

lxsameer14:06:19

hmmmm , very weird. It would be a good candidate for zack to include it in the naming chapter of elements of clojure