March 2020
Intermediate to advanced
406 pages
8h 39m
English
Now that we have a basic understanding of the underlying principles of goroutines, we can check them out in action. In the following code block, we will see how to invoke a goroutine using the go call:
package main import ( "fmt" "time") func printSleep(s string) { for index, stringVal := range s { fmt.Printf("%#U at index %d\n", stringVal, index) time.Sleep(1 * time.Millisecond) // printSleep sleep timer } } func main() { const t time.Duration = 9 go printSleep("HELLO GOPHERS") time.Sleep(t * time.Millisecond) // Main sleep timer fmt.Println("sleep complete")}
During the execution of this function, we only get a partial return of the printSleep() function wrapped in the goroutine call (printing HELLO GOPHERS) before ...
Read now
Unlock full access