ceving <
cev...@googlemail.com> writes:
> On 21 Apr., 14:09, chris dollin <
ehog.he...@googlemail.com> wrote:
>>
>> Because you don't have goroutines.
>>
>
> How can goroutines help if two channel should be read only if on both
> channels is data available?
In a multi-goroutine program, a peek operation on a channel is prone
to race conditions. One goroutine might peek, make some decision, and
then some other goroutine might grab the value. The only reliable way
to read data from two channels at once is to do it atomically. The
language does not provide that operation, and providing it would be
prone to deadlock.
Instead, think of the problem differently. E.g., perhaps you could
put another goroutine in the path which uses select to pull one value
from each channel, puts them together, and sends the pair on a third
channel. Then the rest of your code will always see the objects in
pairs.
Ian