Created
May 19, 2020 02:00
-
-
Save dtest11/5f59ac5d59f2a44b5f5875108f656756 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 sender(out chan<- int) { | |
for { | |
time.After(1 * time.Second) | |
out <- 1 | |
} | |
} | |
// <-chan //只读 | |
func receive(in <-chan int) { | |
for { | |
select { | |
case <-in: | |
fmt.Println("in") | |
} | |
} | |
} | |
func main() { | |
c := make(chan int) // chan //读写 | |
go sender(c) | |
receive(c) | |
fmt.Println("done") | |
<-time.After(1 * time.Hour) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment