The answer depends on whether you have just one value or many. For a single
value (sometimes known as a "future"), I tend to pair a chan of struct{}
with a value to be set. To make the value available, set it, then close the
channel. Readers wait on the channel, then read the value.

For a succession of values, there are lots of possible choices, depending
on what semantics you require. If you can discard intermediate values when
the producer is faster than the consumer, then this package might fit the
bill. https://godoc.org/github.com/juju/utils/voyeur

Watch out though: broadcast values are easy to get wrong as ownership is
not clear. This is one case where better support for immutable data
structures in Go might be useful.

Hope this helps,
  rog.

On 15 Oct 2017 21:36, "st ov" <so.qu...@gmail.com> wrote:

> A value sent through a channel can be read by only one reader, so once its
> read its no longer available to other readers is that right?
>
> In what ways can I pass/communicate/distribute a value through a channel
> and have it shared across an unknown number of readers?
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to