September 2017
Intermediate to advanced
466 pages
9h 33m
English
In this subsection, we will present a simple program that creates two goroutines. The name of the sample program will be aGoroutine.go and will be presented in three parts; the first part is the following:
package main
import (
"fmt"
"time"
)
func namedFunction() {
time.Sleep(10000 * time.Microsecond)
fmt.Println("Printing from namedFunction!")
}
Apart from the expected package and import statements, you can see the implementation of a function named namedFunction() that sleeps for a while before printing a message on the screen.
The second part of aGoroutine.go contains the following Go code:
func main() {
fmt.Println("Chapter 09 - Goroutines.")
go namedFunction()
Here, you create a goroutine that executes the namedFunction() ...
Read now
Unlock full access