буферизированный канал

This commit is contained in:
badkaktus 2019-10-07 22:03:06 +03:00
parent 8461d2c8e4
commit 85d5b5771d
2 changed files with 13 additions and 13 deletions

View File

@ -21,7 +21,7 @@ Switch
Ошибки (Errors)
Горутины (Goroutines)
Каналы (Channels)
Channel Buffering
Буферизированный канал (Channel Buffering)
Channel Synchronization
Channel Directions
Select

View File

@ -1,9 +1,9 @@
// By default channels are _unbuffered_, meaning that they
// will only accept sends (`chan <-`) if there is a
// corresponding receive (`<- chan`) ready to receive the
// sent value. _Buffered channels_ accept a limited
// number of values without a corresponding receiver for
// those values.
// По умолчанию каналы _не буферизованы_, это означает,
// что они будут принимать отправления (`chan <-`), только
// если есть соответствующий прием (`<- chan`), готовый
// принять отправленное значение. _Буферизованные каналы_
// принимают ограниченное количество значений без
// соответствующего приемника для этих значений.
package main
@ -11,17 +11,17 @@ import "fmt"
func main() {
// Here we `make` a channel of strings buffering up to
// 2 values.
// Здесь мы `создаем` канал строк с буфером до 2
// значений.
messages := make(chan string, 2)
// Because this channel is buffered, we can send these
// values into the channel without a corresponding
// concurrent receive.
// Т.к. этот канал буферизирован, мы можем послать
// значения в канал без соответствующего одновременного
// получения.
messages <- "buffered"
messages <- "channel"
// Later we can receive these two values as usual.
// Позже мы можем получить эти значения как обычно.
fmt.Println(<-messages)
fmt.Println(<-messages)
}