March 2020
Intermediate to advanced
406 pages
8h 39m
English
Selects are a construct that allow you to combine goroutines and channels in a meaningful way. We can multiplex Go functions in order to be able to execute a case that occurs when the goroutine is run. In our example, we create three separate channels: a string channel, a bool channel, and a rune channel. We next run some anonymous functions in the following code blocks in order to populate data in those channels, and use the select built-in to return values from the channels.
package main import ( "fmt" "time") func main() { // Make 3 channels ch1 := make(chan string) ch2 := make(chan bool) ch3 := make(chan rune)
Read now
Unlock full access