diff --git a/examples.txt b/examples.txt index 1fdaa6e..f61d431 100644 --- a/examples.txt +++ b/examples.txt @@ -19,7 +19,7 @@ Switch Методы (Methods) Интерфейсы (Interfaces) Ошибки (Errors) -Goroutines +Горутины (Goroutines) Channels Channel Buffering Channel Synchronization diff --git a/examples/goroutines/goroutines.go b/examples/goroutines/goroutines.go index 4943ec9..4282f11 100644 --- a/examples/goroutines/goroutines.go +++ b/examples/goroutines/goroutines.go @@ -1,4 +1,4 @@ -// A _goroutine_ is a lightweight thread of execution. +// _Горутины_ - это легковесный тред. package main @@ -15,25 +15,25 @@ func f(from string) { func main() { - // Suppose we have a function call `f(s)`. Here's how - // we'd call that in the usual way, running it - // synchronously. + // Предположим, у нас есть вызов функции `f(s)`. Вот + // как мы бы вызвали её обычным способом, запустив + // синхронно. f("direct") - // To invoke this function in a goroutine, use - // `go f(s)`. This new goroutine will execute - // concurrently with the calling one. + // Чтобы вызвать эту функцию в горутине, используйте + // `go f(s)`. Эта новая горутина будет выполняться + // одновременно с вызывающей фукнцией. go f("goroutine") - // You can also start a goroutine for an anonymous - // function call. + // Вы так же можете вызывать анонимные функции в + // горутнах. go func(msg string) { fmt.Println(msg) }("going") - // Our two function calls are running asynchronously in - // separate goroutines now. Wait for them to finish - // (for a more robust approach, use a [WaitGroup](waitgroups)). + // Наши две функции теперь выполняются асинхронно в + // отдельных горутинах. Дождитесь их окончания (для + // более надежного подхода используйте [WaitGroup](waitgroups)). time.Sleep(time.Second) fmt.Println("done") } diff --git a/examples/goroutines/goroutines.sh b/examples/goroutines/goroutines.sh index 1d42ee2..aae9dba 100644 --- a/examples/goroutines/goroutines.sh +++ b/examples/goroutines/goroutines.sh @@ -1,7 +1,7 @@ -# When we run this program, we see the output of the -# blocking call first, then the interleaved output of the -# two goroutines. This interleaving reflects the -# goroutines being run concurrently by the Go runtime. +# Когда мы запускаем эту программу, мы видим сначала +# вывод блокирующего вызова, а затем чередующийся вывод +# двух горутин. Это чередование отражает выполнение +# горутин, одновременно выполняемых средой выполнения Go. $ go run goroutines.go direct : 0 direct : 1 @@ -12,5 +12,5 @@ goroutine : 1 goroutine : 2 done -# Next we'll look at a complement to goroutines in -# concurrent Go programs: channels. +# Далее мы рассмотрим дополнение к горутинам в +# параллельных программах Go: каналы.