Yes Robert's observation that you need all values to merge sorted data, and 
that channels don't provide this.  However, if the implementation receives 
on channels ahead of time, then this isn't a problem because you do have 
one value from each source to decide how to proceed.



On Sunday, 21 October 2018 23:52:37 UTC+2, robert engels wrote:
>
> I don’t think that is correct. If the channels provide sorted async data - 
> you need to have a value available at every channel in order to produce a 
> sorted merged.
>
> The consumer needs to wait until every channel has supplied a value.
>
> Otherwise - imagine 2 channels A,B. A provides 5, B has not provided 
> anything, so you process 5, then B provides 3, oops - out of order…
>
> On Oct 21, 2018, at 1:26 PM, roger peppe <rogp...@gmail.com <javascript:>> 
> wrote:
>
> Channels can work fine for this kind of thing. 
>
> The easiest (but probably a little less efficient) way is to write a 
> function that knows how to merge two channels, then use n-1 of them to 
> merge n channels. Whenever you don't currently have a value from a channel, 
> read one, then output the smallest of the two values that you have.
>
> Alternatively read a value from all channels, then output smallest (you 
> could use a binary heap if n might be large), and read from that value's 
> channel again.
>
>
> On Sun, 21 Oct 2018, 7:53 am Tamás Gulácsi, <tgula...@gmail.com 
> <javascript:>> wrote:
>
>> Do you really want to use channels for this? You can't predict the 
>> selection order and can't peek into a channel, so you have N random 
>> source...
>>
>> -- 
>> 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...@googlegroups.com <javascript:>.
>> 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...@googlegroups.com <javascript:>.
> 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