This section presents two very important techniques that will help you to time out goroutines. Put simply, these two techniques will save you from having to wait forever for a goroutine to finish its job, and they will give you full control over the amount of time that you want to wait for a goroutine to end. Both techniques use the capabilities of the handy select keyword combined with the time.After() function that you experienced in the previous section.
Timing out a goroutine
Timing out a goroutine – take 1
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 ( "...