diff --git a/examples.txt b/examples.txt index f61d431..4420f34 100644 --- a/examples.txt +++ b/examples.txt @@ -20,7 +20,7 @@ Switch Интерфейсы (Interfaces) Ошибки (Errors) Горутины (Goroutines) -Channels +Каналы (Channels) Channel Buffering Channel Synchronization Channel Directions diff --git a/examples/channels/channels.go b/examples/channels/channels.go index 7a5ac9a..ad4c6e9 100644 --- a/examples/channels/channels.go +++ b/examples/channels/channels.go @@ -1,7 +1,6 @@ -// _Channels_ are the pipes that connect concurrent -// goroutines. You can send values into channels from one -// goroutine and receive those values into another -// goroutine. +// _Каналы_ это способ связи паралелльных горутин между +// собой. Вы можете послать сообщение в канал из одной +// горутины и получить его в другой. package main @@ -9,18 +8,19 @@ import "fmt" func main() { - // Create a new channel with `make(chan val-type)`. - // Channels are typed by the values they convey. + // Создаем новый канал - `make(chan val-type)`. + // Каналы типизируются в зависимости от значений, + // которые они передают. messages := make(chan string) - // _Send_ a value into a channel using the `channel <-` - // syntax. Here we send `"ping"` to the `messages` - // channel we made above, from a new goroutine. + // _Отправьте_ значение в канал, используя `channel <-`. + // Здесь мы отправляем `"ping"` в канал `messages`, + // который мы сделали выше, из новой горутины. go func() { messages <- "ping" }() - // The `<-channel` syntax _receives_ a value from the - // channel. Here we'll receive the `"ping"` message - // we sent above and print it out. + // Синтаксис `<-channel` _читает_ из канала. Здесь + // мы получим сообщение `"ping"`, которое мы + // отправили выше, и распечатаем его. msg := <-messages fmt.Println(msg) } diff --git a/examples/channels/channels.sh b/examples/channels/channels.sh index 0d37c18..3d73362 100644 --- a/examples/channels/channels.sh +++ b/examples/channels/channels.sh @@ -1,10 +1,10 @@ -# When we run the program the `"ping"` message is -# successfully passed from one goroutine to another via -# our channel. +# Когда мы запускаем программу, сообщение `"ping"` успешно +# передается из одной горутины в другую по нашему каналу. $ go run channels.go ping -# By default sends and receives block until both the -# sender and receiver are ready. This property allowed -# us to wait at the end of our program for the `"ping"` -# message without having to use any other synchronization. +# По-умолчанию, отправление и получение блокируются, +# пока оба отправителя и получателя готовы. Это +# свойство позволило нам ждать в конце нашей программы +# сообщения `"ping"` без использования какой-либо +# другой синхронизации.