Hello and welcome to the goal and programming language course in this session.
We want to talk about the others concurrency concept.
Select a statement and GO Select is similar to such a statement.
The difference being that in select each of the cases statement, they spot a send or receive operation
from a Channon Select.
The statement will wait until sent or receive operation is completed on any one of the case.
The statement It is different from the Suchas statement in the way that each of the cases statements
will either send or receive operation on a Channon, whereas in sewage each of the case.
The statement is an expression, so a select statement lets you wait on multiple and receive operations
from different channels.
Two important points to note about City's statement is the select ballots.
Until any of the case, the statements are ready, and if multiple cases statements are ready, then
it selects one at random and proceeds.
The following rules apply to select statement.
You can have any number of cases statements within a select.
Each case is followed by the value to be compared to and the column.
The time for a case must be a communication channel operation.
When the channel operation accurate statements following that case will execute.
No break is needed in case a statement is select.
The statement can have in the optional default case, which must appear at the end of the select.
The default case can be used for performing a task then known of the case is true.
No work is needed in different chase.
Now you can see the scene techs.
Select chooses the case on which send or receive operation on a channel is not blocked and is ready
to be executed.
If multiple cases are ready to be executed, then one is chosen at random.
Now let's go to this school with program to see how to use select statements.
First, create two functions that accept arguments as extreme Channel five.
Hello.
Set a variable like search by the time string
set value to channel search channel operator, for example.
Hello and create another function, for example by phone by set a variable.
By the time it's strange
and assign a string value to channel, for example, search channel operator and goodbye.
Now go to main function to create two channel and commands these two go routines.
First, define a variable like Sichuan call equals calling make function.
By the time a string and define another channel like search, two column equals make function by the
time is now calling hello and by function in past these Channon as arguments to then go Hello Sichuan.
And in the next line, cutting another function go by.
And it seems to, as our humans do it now we define a select statement for handling channels.
Select
Define First Case and reset channel value.
Case value one calling equals channel operator.
Search one column and print value of this channel.
FP Value one.
And Define Second Case and fetch channel value.
Case Value two column equals channel operator search two and now print value of Bystrom.
If the value to reformat the code, save the project and execute the program, go from Duck's back to
me.
That's cool.
Now we can see the outputs in their bound program.
We created two channels that are passed to two different go routines.
Then each of the go routines is sending one value through the channel in the cell.
We have to chase the statement.
Each of the two cases statement is waiting for receive operation to complete on one of the channels
once and receive operation is complete on any of the channels it is executed in select exec.
So as seen from the output in the above program, it drains the received value from one of the challenges
and.
And now we say goodbye.
So in the about program, since it is not deterministic, which of the sand operation will complete
earlier?
That is why you will see different outputs if you run the program multiple times.
So in this example, we could use select statement.
We have reached the end of decision.
I hope you have taken full advantage of decision on the next edition.
Goodbye.