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

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) Ошибки (Errors)
Горутины (Goroutines) Горутины (Goroutines)
Каналы (Channels) Каналы (Channels)
Channel Buffering Буферизированный канал (Channel Buffering)
Channel Synchronization Channel Synchronization
Channel Directions Channel Directions
Select Select

View File

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