September 2017
Intermediate to advanced
466 pages
9h 33m
English
The technique of this subsection will let you not wait for any stubborn goroutines to finish their jobs. Therefore, this subsection will show you how to time out goroutines with the help of the timeoutWait.go program that will be presented in four parts. Despite the code differences between timeoutWait.go and timeOuts.go, the general idea is exactly the same.
The first part of timeoutWait.go contains the expected preamble:
package main import ( "fmt" "sync" "time" )
The second part of timeoutWait.go is the following:
func timeout(w *sync.WaitGroup, t time.Duration) bool { temp := make(chan int) go func() { defer close(temp) w.Wait() }() select { case <-temp: return false case <-time.After(t): return ...Read now
Unlock full access