August 2019
Beginner to intermediate
798 pages
17h 2m
English
Although neither readCh.go nor writeCh.go used this feature, Go allows you to specify the direction of a channel when used as a function parameter; that is, whether it will be used for reading or writing. These two types of channels are called unidirectional channels, whereas, by default, channels are bidirectional.
Examine the Go code of the following two functions:
func f1(c chan int, x int) {
fmt.Println(x)
c <- x
}
func f2(c chan<- int, x int) {
fmt.Println(x)
c <- x
}
Although both functions implement the same functionality, their definitions are slightly different. The difference is created by the <- symbol found on the right of the chan keyword in the definition of the f2() function. This denotes that ...
Read now
Unlock full access