What is the use of buffered pipes in Go?

As far as I understand from this question, " Golang - What is channel buffer size? ", If the channel is buffered, it will not be blocked.

c := make(chan int, 1)
c <- data1 // doesn't block
c <- data2 // blocks until another goroutine receives from the channel
c <- data3
c <- data4

But I do not understand what its use is. Suppose that if I have 2 goroutines, the first will receive data1, and the second will receive data2, then it will be blocked until some routines are freed for data processing3.

I don’t understand, what's the difference? This would also be done without a buffer. Can you explain a possible scenario when buffering is useful?

+4
source share
2 answers

goroutine , -, , , .

, goroutine, HTTP-, , . , , , , . , HTTP goroutine . goroutines , . HTTP-, HTTP, .

+4

Source: https://habr.com/ru/post/1534145/


All Articles