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?
yes, very common
@colinkahn also common to use some?
as the predicate so that you can send any value including false
over the channel (but not nil
)
would you use some?
when building the channel? Like (a/chan (filter some?))
no
when reading it
as your recur condition
Ah ok, so like a (when-some [x (a/<! my-chan)] ...)
should suffice
exactly
the channel already rejects nil
values when putting them in -- you shouldn't try to duplicate this "in userspace"
gotcha, and even with the filter
it’ll still emit nil
upon close, if I understand correctly
no, your code would just be stopped indefinitely reading nils
and probably pegging the CPU
oh alright, so yeah, I have to handle the nil
case to break the loop
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
right
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)
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
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..)
Thanks, this definitely makes it clearer