August 2019
Beginner to intermediate
798 pages
17h 2m
English
In this subsection, you will learn two ways of creating goroutines. The first one is by using regular functions, while the second method is by using anonymous functions – these two ways are equivalent.
The name of the program covered in this section is simple.go, and it is presented in three parts.
The first part of simple.go is the following Go code:
package main
import (
"fmt"
"time"
)
func function() {
for i := 0; i < 10; i++ {
fmt.Print(i)
}
}
Apart from the import block, the preceding code defines a function named function() that will be used in a short while.
The function name function() is nothing special – you can give it any valid function name you want.
The second part of simple.go is as follows:
func main() ...
Read now
Unlock full access