Select Statement
This lesson will introduce you to multi-way concurrent control in Go: the select statement.
We'll cover the following...
We'll cover the following...
The select statement blocks the code and waits for multiple channel operations simultaneously.
Syntax
The syntax for the select statement is as follows:
Example
Let’s try to understand the usage of a select statement with a simple example consisting of two channels which are communicating using send/receive operations:
In the code above, we have two goroutines, each of which is sending messages on each of the two channels.
The first goroutine sends a message I'll print every 100ms and then waits for 100ms before sending the message again in the next iteration.
go func() {
for i := 0; i < 5; i++ ...