August 2019
Beginner to intermediate
798 pages
17h 2m
English
The source code of the first technique will be saved in timeOut1.go, and it will be presented in four parts.
The first part of timeOut1.go is shown in the following Go code:
package main
import (
"fmt"
"time"
)
The second code segment from timeOut1.go is as follows:
func main() {
c1 := make(chan string)
go func() {
time.Sleep(time.Second * 3)
c1 <- "c1 OK"
}()
The time.Sleep() call is used to emulate the time it will normally take for the function to finish its job. In this case, the anonymous function that is executed as a goroutine will take about three seconds (time.Second * 3) before writing a message to the c1 channel.
The third code segment from timeOut1.go contains the following Go code:
select { ...Read now
Unlock full access