Hello and welcome to the Golang programming language course in this session, we want to talk about
the others concurrency concept.
Closing a Shannon.
You can also close the channel with the help of close function.
This is an e-mail function and sets of flag, which indicates that no more value will send to this channel.
Now you can see the syntax.
You can honestly close the channel using four lanes loop here the receiver go routine can check the
channel is open or close with the help of the given syntax.
Here, if the value of okay is true, which means the channel is open, so read operations can be performed.
And if the value of eats falls, which means the channel is closed, so read operations are not going
to perform.
Now let's go to this school with program to illustrate how to close a channel using for close function
in range loop.
First, define the function that sends string value to channel, so we write farm send and create a
variable like C-H churn by the type as switch.
And defining the for loop, Ford defined the valley to like we call an equals zero the less than four
and v + +
c h channel operator, for example GO program.
And
now here close the Channel Close channel.
Now we go to main function and create a channel
defining variable like search calling equals tiny main function.
By the time is
now calling defined function as go routine, and since this variable as a channel variable goal setting
and Porsche's variable at arguement now create a full in regional value for.
Defined two variables like resolved and OK in fit channel data.
These are common.
OK.
Colin equals.
OK, then the value of orca is set to true means the channel is open and it can send or receive data
when the value of orca is set to false means, the channel is closed.
So right below statements for handling channel is not OK if the channel closed and said look and bridge.
And if program doesn't go to if a state, then so do not break and we right channel open the statement
FP
China, okay, and search for visa and or reformat the code, save the project and execute the program.
Go round dot backslash main dot gov.
Now we can see the output in the above program.
We created the same function the go routine that accept the channel and send four times goal programming
volume channel.
And after that, we use close function to close the channel, indicating that no more values can be
sent to the channel after it go to main function, create a channel and pass it to send function as
argument in Colin, go rotten in its race over the channel and read value of channel in order not to
prolong the time of decision.
We will finish it and we will continue the content in the next session.
Goodbye.