filmov
tv
Go (golang) Tutorials - Buffered Channels

Показать описание
#golang #go #concurrency #channels
Concurrency - Buffered Channels
--------------------------------
= Similar to regular channels but they have some buffer size to store values
= The channel send operations will remain un blocking until the buffer slots are available
= Once the buffer slots got filled up, then the send channels will be blocking as usual
-----------
package main
import "fmt"
func main(){
//There is no wait/sleep operation in main go routine
channel:=make(chan int, 2) //Create a buffered channel of capacity 2
channel(arrow operator)10 //Sending two values to the channel
channel(arrow operator)20
//channel(arrow operator)30
fmt.Printf("%d\n",len(channel))
fmt.Printf("%d\n",(arrow operator)channel)
fmt.Printf("%d\n",len(channel))
fmt.Printf("%d\n",(arrow operator)channel) //Receiving two values from the channel
fmt.Printf("%d\n",cap(channel))
}
Concurrency - Buffered Channels
--------------------------------
= Similar to regular channels but they have some buffer size to store values
= The channel send operations will remain un blocking until the buffer slots are available
= Once the buffer slots got filled up, then the send channels will be blocking as usual
-----------
package main
import "fmt"
func main(){
//There is no wait/sleep operation in main go routine
channel:=make(chan int, 2) //Create a buffered channel of capacity 2
channel(arrow operator)10 //Sending two values to the channel
channel(arrow operator)20
//channel(arrow operator)30
fmt.Printf("%d\n",len(channel))
fmt.Printf("%d\n",(arrow operator)channel)
fmt.Printf("%d\n",len(channel))
fmt.Printf("%d\n",(arrow operator)channel) //Receiving two values from the channel
fmt.Printf("%d\n",cap(channel))
}
Комментарии