You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
341 B
30 lines
341 B
12 years ago
|
package main
|
||
|
|
||
12 years ago
|
import (
|
||
12 years ago
|
"fmt"
|
||
|
"time"
|
||
12 years ago
|
)
|
||
12 years ago
|
|
||
|
func main() {
|
||
12 years ago
|
c := make(chan int, 2)
|
||
|
q := make(chan bool)
|
||
12 years ago
|
|
||
12 years ago
|
go func(c chan int) {
|
||
|
for i := range c {
|
||
|
fmt.Println("\t", i, "<- popped")
|
||
|
time.Sleep(300 * time.Millisecond)
|
||
|
}
|
||
|
}(c)
|
||
12 years ago
|
|
||
12 years ago
|
go func(c chan int) {
|
||
|
i := 0
|
||
|
for {
|
||
|
c <- i
|
||
|
fmt.Println("pushed ->", i)
|
||
|
i += 1
|
||
|
}
|
||
|
}(c)
|
||
12 years ago
|
|
||
12 years ago
|
<-q
|
||
12 years ago
|
}
|