Skip to content

Instantly share code, notes, and snippets.

@dtest11
Created May 19, 2020 02:00
Show Gist options
  • Save dtest11/5f59ac5d59f2a44b5f5875108f656756 to your computer and use it in GitHub Desktop.
Save dtest11/5f59ac5d59f2a44b5f5875108f656756 to your computer and use it in GitHub Desktop.
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