#What is the difference between an unbuffered channel and a buffered channel of size one?

11 messages · Page 1 of 1 (latest)

thin marsh
#

^

tawdry ore
#

If you try to write to an unbuffered channel, it'll block until someone reads it

#

If you write to a buffered channel it won't block unless the channel is full

#

So the first write will block in unbuffered
But the first write won't block in buffered of size 1

thin marsh
#

So if a goroutine tries to write into a channel that no one listens to, it will block until a consumer comes and reads from the channel?

tawdry ore
#

Yes

#

Same with reads btw

#

If you try to read from an empty channel, it'll block until someone writes to it

thin marsh
#

correct..is there anything else to it?

tawdry ore
#

Not really

#

It's pretty simple