initial commit
This commit is contained in:
commit
493ce92e02
62 changed files with 1213 additions and 0 deletions
BIN
channel-directions/channeldirections
Executable file
BIN
channel-directions/channeldirections
Executable file
Binary file not shown.
25
channel-directions/channeldirections.go
Normal file
25
channel-directions/channeldirections.go
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
//this func only accepts a channel for sending values.
|
||||
//it would be a compile-time error
|
||||
//to try to receive on this channel.
|
||||
func ping(pings chan<- string,msg string){
|
||||
pings <- msg
|
||||
}
|
||||
|
||||
//this pong function accepts one channel for receives (pings)
|
||||
//and a second for sends(pongs)
|
||||
func pong(pings <-chan string, pongs chan<- string) {
|
||||
msg := <-pings
|
||||
pongs <- msg
|
||||
}
|
||||
|
||||
func main() {
|
||||
pings := make(chan string, 1)
|
||||
pongs := make(chan string, 1)
|
||||
ping(pings, "passed message")
|
||||
pong(pings,pongs)
|
||||
fmt.Println(<-pongs)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue