Created
April 24, 2018 06:19
-
-
Save aggresss/dc525d6fb75fa2af4b7b11b055ceb689 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"time" | |
) | |
func main() { | |
c := make(chan int) | |
go send(c) | |
go recv(c) | |
time.Sleep(30 * time.Second) | |
} | |
//只能向chan里写数据 | |
func send(c chan<- int) { | |
for i := 0; i < 10; i++ { | |
time.Sleep(1 * time.Second) | |
c <- i | |
} | |
} | |
//只能取channel中的数据 | |
func recv(c <-chan int) { | |
for i := range c { | |
fmt.Println(i) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.cnblogs.com/baiyuxiong/p/4545028.html