0
votes

Given a channel in ClojureScript

(def navigation (chan))

Is it possible to have multiple go blocks that pull values off it? E.g.

(go
 (while true
   (secretary/dispatch! (<! navigation))))

(go
 (while true
   (println (<! navigation))))

The putting a value in with:

(put! channels/navigation "/styles")

This doesn't seem to work and only executes within the first Go block. This is a bit of a contrived example but I do want to use this pattern to have multiple listeners to a channel that will return JSON from a socket.io service.

2

2 Answers

2
votes

Reading from a channel will return the value and remove it from the channel. If you want multiple readers to read the same values you need multiple channels; take look at the core.async mult and tap functions.

0
votes

You might want to look into the pub and sub functions in core.async. This still means multiple channels as @Joost mentioned.