February 2019
Intermediate to advanced
450 pages
11h 59m
English
To demonstrate the problem, let's start with a simple goroutine demo; we'll launch three threads that print progress. For each thread, we'll print Started followed by . until the thread stops, at which point Ended will be printed:
package mainimport ( "fmt" "time")func tick() { fmt.Println("Started") for _ = range time.NewTicker(time.Second).C { fmt.Print(".") } fmt.Println("Ended")}func main() { go tick() go tick() go tick() time.Sleep(5 * time.Second)}
If you run this code, you'll see the following output. The threads start and tick as expected and, after a 5 second timeout, the program exits. No Ended messages are seen:
As you can see from this simple demo, the goroutines aren't ...
Read now
Unlock full access