initial commit
This commit is contained in:
commit
493ce92e02
62 changed files with 1213 additions and 0 deletions
BIN
channels/channels
Executable file
BIN
channels/channels
Executable file
Binary file not shown.
22
channels/channels.go
Normal file
22
channels/channels.go
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
|
||||
//Channels are the pipes that connect concurrent goroutines.
|
||||
//you can send values into channels
|
||||
//form one goroutine and receive those values into another goroutine
|
||||
func main(){
|
||||
//create a new channel with make(chan val-type)
|
||||
//Channels are typed bt the values they convey
|
||||
messages := make(chan string)
|
||||
|
||||
//send a value into a channel using the channel <- syntax.
|
||||
//here we send "ping" to the messages channel we made above, from a new goroutine
|
||||
go func() { messages <- "ping"}()
|
||||
|
||||
//the <- channel syntax receives a value from the channel.
|
||||
// here we'll receive the "ping" message we sent above and print it out
|
||||
msg := <- messages
|
||||
fmt.Println(msg)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue