Go (golang) Tutorials - Closing channels and Iteration

Published: 12 April 2018
on channel: Ambasoft Java
870
20

#golang #go #concurrency #channels

Concurrency - Closing Channels
--------------------------------
Closing Channels After Sending values to it
Iterating to Read from a Channel

closedemo.go
--------------
package main
import "fmt"
func display(mychannel chan int){
fmt.Println("Display goroutine")
//Use for loop {
mychannel(arrow operator)i //Send a set of i values iteratively to the channel mychannel
}
close(mychannel)
}
func main(){
mychannel:=make(chan int)
go display(mychannel)
/* for { //Indeterminate for loop with no control variable
num,status:=(arrow operator)mychannel //Read a value from mychannel
if status==false{ //If channel is closed
break
}
fmt.Printf("Main goroutine:%d\n",num)
}*/
for value:=range mychannel { //For range loop iterates until the channel has values
fmt.Println(value)
}
}


Watch video Go (golang) Tutorials - Closing channels and Iteration online, duration hours minute second in high quality that is uploaded to the channel Ambasoft Java 12 April 2018. Share the link to the video on social media so that your subscribers and friends will also watch this video. This video clip has been viewed 870 times and liked it 20 visitors.