Fork me on GitHub
#core-async
<
2018-04-05
>
stephenmhopper14:04:47

Is there a way to consume messages from a core.async channel multiple times in CLJS?

matthavener15:04:31

@stephenmhopper like read a message without “removing” it from the channel?

stephenmhopper15:04:56

@matthavener Yeah. I was mostly asking with regard to caching cljs-http responses that I'm getting as single responses on a core.async channel. I discovered that I could just pipe that channel to a promise-chan to achieve the desired effect. However, I'm still curious if there's a general way to read from a channel without consuming in CLJ (not just CLJS). Can I use eduction to achieve that effect?

bjr16:04:09

it looks like a promise-chan, as you found, is exactly what you want. it’s a channel with a buffer implementation where reading doesn’t remove the value from the buffer. https://github.com/clojure/core.async/blob/master/src/main/clojure/cljs/core/async/impl/buffers.cljs#L145

bjr16:04:48

you cannot in general perform a take on a channel without consuming the item, but a buffer can choose to supply the channel with the same value endlessly

matthavener15:04:01

hm, not sure about eduction, but you could wrap the channel in a buffer

matthavener15:04:25

a chan can be totally unbuffered

Alex Miller (Clojure team)16:04:10

you can’t read without consuming