Messages and events

So far we have been using the term data to refer to the values that are being sent and received from a channel. While this might be easy to understand so far, Go uses two specific terms to describe the type of data that is being communicated over the channels. They are called messages and events. In terms of code they are identical, but the terms are used to help us understand the type of data that is being sent. In a nutshell:

  • Messages are generally values we want the goroutine to process and act on them if required.
  • Events are used to signify that a certain event has occurred. The actual value received might not be as important as the act of receiving a value. Note that though we use the term event, they are still a type of message.

In the previous code example, values sent to ch are messages, while the value sent to done is an event. An important point to note is that element types of event channels tend to be struct{}{}, bool, or int.

Now that we understand what channel element types, messages, and events are, let's look at the different types of channels.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.144.170