February 2019
Intermediate to advanced
450 pages
11h 59m
English
First, let's examine the most basic Go concurrency feature: the goroutine. Any normal function, when called, will execute the code inside and exit when return is encountered, or the function exits—at which point it will return control to the function that invoked it. A goroutine is one that starts execution, but immediately returns control to the function calling it—essentially creating a background process for each invocation. Any function can be called as a goroutine simply by prefixing go to the invocation, as follows:
package mainimport ( "fmt" "time")func tick(message string) { for i := 0; i < 5; i++ { time.Sleep(10 * time.Millisecond) fmt.Println(message) }}func main() { go tick("goroutine") tick("function")}
This code sample ...
Read now
Unlock full access