January 2020
Intermediate to advanced
640 pages
16h 56m
English
As we saw in Chapter 9, Communicating with the Outside World, bi-directional gRPC streams are full-duplex; the receive and send channels operate independently of each other. However, reading from a gRPC stream is a blocking operation. Therefore, to process both sides of the stream, we need to spin up some goroutines.
Another important caveat of gRPC streams is that, while we can call Recv and Send from different goroutines, calling each of these methods concurrently from different goroutines is not safe and can lead to data loss! Therefore, we need a mechanism to serialize send and receive operations on the gRPC stream. The kind of obvious Go primitives for exactly this type ...