edits
This commit is contained in:
parent
b044506449
commit
e6a3c56d77
@ -1,7 +1,7 @@
|
|||||||
// When using channels as function parameters, you can
|
// When using channels as function parameters, you can
|
||||||
// specify if a channel is meant to only send or receive
|
// specify if a channel is meant to only send or receive
|
||||||
// values. This specificity further increases the
|
// values. This specificity increases the type-safety of
|
||||||
// type-safety of the program.
|
// the program.
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
@ -15,7 +15,7 @@ func ping(pings chan<- string, msg string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The `pong` function accepts one channel for receives
|
// The `pong` function accepts one channel for receives
|
||||||
// (`pings`) and a second for sends (`pongs`)
|
// (`pings`) and a second for sends (`pongs`).
|
||||||
func pong(pings <-chan string, pongs chan<- string) {
|
func pong(pings <-chan string, pongs chan<- string) {
|
||||||
msg := <-pings
|
msg := <-pings
|
||||||
pongs <- msg
|
pongs <- msg
|
||||||
|
@ -13,7 +13,7 @@ import "time"
|
|||||||
func worker(done chan bool) {
|
func worker(done chan bool) {
|
||||||
fmt.Print("working...")
|
fmt.Print("working...")
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
fmt.Println(" done")
|
fmt.Println("done")
|
||||||
|
|
||||||
// Send a value to notify that we're done.
|
// Send a value to notify that we're done.
|
||||||
done <- true
|
done <- true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user