Groups | Search | Server Info | Login | Register


Groups > comp.lang.go > #53

Re: buffered channel

From a cat <a_cat@example.com>
Newsgroups comp.lang.go
Subject Re: buffered channel
Date 2024-04-16 09:58 -0600
Organization A noiseless patient Spider
Message-ID <uvm76b$10vmp$1@dont-email.me> (permalink)
References <of1l1jpps6ckrs5ssuuskpts76rk1mnhue@4ax.com> <868r1f25gr.fsf@building-m.net>

Show all headers | View raw


On 4/14/24 11:56, John wrote:
> Rob <usenet@drrob1.com> writes:
> 
>> I'm looking to better understand buffered channels.
>>
>> I understand that using a buffer of 1 prevents certain kinds of
>> goroutine leaks
>>
>> Are their any guidelines or caviats on how big to make the buffer size
>> for a channel?
>>
>> Thanks
>> Rob
> 
> It's not a magic bullet to prevent goroutine leaks... I guess the
> advantage of setting the size to 1 means that the writing goroutine will
> be able to write and exit, even if you forget to read the channel
> elsewhere.
> 
> If your code falls over with a buffer size of 10, it'll probably fall
> over (but slower) with a buffer size of 1000 -- that, or it'll
> "complete" but still be wrong.
> 
> john

I agree. I would start out using unbuffered channels until you know that 
you need a buffered one, and why. Buffered channels can hide bugs.

Back to comp.lang.go | Previous | NextPrevious in thread | Find similar


Thread

buffered channel Rob <usenet@drrob1.com> - 2024-04-13 09:19 -0400
  Re: buffered channel John <john@building-m.simplistic-anti-spam-measure.net> - 2024-04-14 17:56 +0000
    Re: buffered channel a cat <a_cat@example.com> - 2024-04-16 09:58 -0600

csiph-web