Re: [go-nuts] Re: How to pass a value to multiple readers of a shared channel

2017-10-18 Thread Юрий Соколов
Between those two lines (fetching value from channel and sending it back to channel) channel is empty. This leads to two possible errors: - less dangerous is if some checks channel in non-blocking mode (ie select with default). Then it sees empty channel and thinks value is not set yet. - more

Re: [go-nuts] Re: How to pass a value to multiple readers of a shared channel

2017-10-18 Thread roger peppe
On 18 October 2017 at 06:05, Sokolov Yura wrote: > Following is a dangerous error-prone technique. If you use it in you program, > most likely you have a hidden bug, that will appear in high concurrency > situation. > > ``` > func wait(c chan T) T { > v :=

[go-nuts] Re: How to pass a value to multiple readers of a shared channel

2017-10-17 Thread Sokolov Yura
Following is a dangerous error-prone technique. If you use it in you program, most likely you have a hidden bug, that will appear in high concurrency situation. ``` func wait(c chan T) T { v := <-c c <- v; return v; } ``` I had proposal for future primitive:

Re: [go-nuts] Re: How to pass a value to multiple readers of a shared channel

2017-10-17 Thread Jesper Louis Andersen
If you have serious performance needs, then something like the "Disruptor" pattern is useful. There are ports of that from Java to Go out there, but I don't know how stable or useful they are. The Disruptor pattern is to keep a circular ring-buffer of elements. The writer and each reader keeps

[go-nuts] Re: How to pass a value to multiple readers of a shared channel

2017-10-17 Thread st ov
that's an great article thank you! On Sunday, October 15, 2017 at 6:51:03 PM UTC-7, dja...@gmail.com wrote: > > This post might help: > > https://rogpeppe.wordpress.com/2009/12/01/concurrent-idioms-1-broadcasting-values-in-go-with-linked-channels/ > > Djadala > > On Sunday, October 15, 2017 at

[go-nuts] Re: How to pass a value to multiple readers of a shared channel

2017-10-16 Thread rene . reichenbach
https://golang.org/pkg/io/#TeeReader should help you out best, Rene Am Sonntag, 15. Oktober 2017 22:36:36 UTC+2 schrieb st ov: > > 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

[go-nuts] Re: How to pass a value to multiple readers of a shared channel

2017-10-15 Thread wolf0403
My feeling is that a variable paired with a sync.Cond might be the right choice if you are broadcasting a single value change. I can't think of an readily available lib / language feature to support broadcasting multiple value change though. On Monday, 16 October 2017 06:36:36 UTC+10, st ov

[go-nuts] Re: How to pass a value to multiple readers of a shared channel

2017-10-15 Thread djadala
And here is some working code: https://play.golang.org/p/1Qt-LqKiph Djadala On Sunday, October 15, 2017 at 11:36:36 PM UTC+3, st ov 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

[go-nuts] Re: How to pass a value to multiple readers of a shared channel

2017-10-15 Thread djadala
This post might help: https://rogpeppe.wordpress.com/2009/12/01/concurrent-idioms-1-broadcasting-values-in-go-with-linked-channels/ Djadala On Sunday, October 15, 2017 at 11:36:36 PM UTC+3, st ov wrote: > > A value sent through a channel can be read by only one reader, so once its > read its no