Blocking a goroutine
Blocking a goroutine can be important. The easiest example of this is the main
function. If we have no blocking call or loop inside the main
function, the program terminates and restarts. In most cases, we do not want a program to terminate, as we might want to wait for a signal on any input that could trigger any further action in the code.
Let's now look at some possibilities for blocking a goroutine. Blocking a goroutine is sometimes necessary in order to gain time to let a scheduler work on other goroutines.
Reading from a channel
A very common way to block a goroutine is to read from a channel. Reading from a channel blocks the goroutine until a value can be read. This is illustrated in the following code example:
func main() {       blocker := make(chan bool, 1)      <-blocker      println("this gets never printed") }
A select statement
A select...