September 2017
Intermediate to advanced
466 pages
9h 33m
English
A signal channel is a channel that is used just for signaling. Signal channels will be illustrated using the signalChannel.go program with a rather unusual example that will be presented in five parts. The program executes four goroutines: when the first one is finished, it sends a signal to a signal channel by closing it, which will unblock the second goroutine. When the second goroutine finishes its job, it closes another channel that unblocks the remaining two goroutines. Note that signal channels are not the same as channels that carry the os.Signal values.
The first part of the program is the following:
package main import ( "fmt" "time" ) func A(a, b chan struct{}) { <-a fmt.Println("A!") time.Sleep(time.Second) close(b) ...Read now
Unlock full access