core-async

2019-06-26T22:08:01.137700Z

When handling values from a channel, is it correct that when the channel closes the value will be nil? And, is it common to have to cover that case for each go block? For example if I have a go-loop and a channel i’m consuming returns nil I would stop recuring that loop?

ghadi 2019-06-26T22:21:31.137900Z

yes, very common

ghadi 2019-06-26T22:22:14.138800Z

@colinkahn also common to use some? as the predicate so that you can send any value including false over the channel (but not nil)

2019-06-26T22:23:33.139800Z

would you use some? when building the channel? Like (a/chan (filter some?))

ghadi 2019-06-26T22:26:10.140400Z

no

ghadi 2019-06-26T22:26:12.140600Z

when reading it

ghadi 2019-06-26T22:26:40.141100Z

as your recur condition

2019-06-26T22:27:15.142Z

Ah ok, so like a (when-some [x (a/<! my-chan)] ...) should suffice

ghadi 2019-06-26T22:27:20.142300Z

exactly

ghadi 2019-06-26T22:27:49.143200Z

the channel already rejects nil values when putting them in -- you shouldn't try to duplicate this "in userspace"

2019-06-26T22:28:29.144600Z

gotcha, and even with the filter it’ll still emit nil upon close, if I understand correctly

2019-06-26T22:29:08.145500Z

no, your code would just be stopped indefinitely reading nils

2019-06-26T22:29:14.145800Z

and probably pegging the CPU

2019-06-26T22:29:46.146900Z

oh alright, so yeah, I have to handle the nil case to break the loop

2019-06-26T22:29:54.147200Z

or maybe I misunderstood you: the channel keeps making nils as fast as you ask for them, filter would just drop them all before other code sees them

2019-06-26T22:29:55.147400Z

right

dpsutton 2019-06-26T22:30:27.148300Z

I'm not sure how impactful it is. But the timer's skiplist in cljs is just a simple linked list not a skip list. https://clojure.atlassian.net/projects/ASYNC/issues/ASYNC-228. Would appreciate someone chiming in if they think this is major or not (while people are in here chatting)

2019-06-26T22:30:53.149Z

on the other hand there is take-while which stops after some condition is met, but I wouldn't recommend treating IO like channel ops as if they were lazy collections

2019-06-26T22:31:15.149500Z

yeah I want to be able to create some go blocks but when I close the channels that they use all of those blocks are closed too (not sure the correct terminology for when a go block ends..)

2019-06-26T22:32:35.150100Z

Thanks, this definitely makes it clearer