More goofing around with buffered channels
This commit is contained in:
parent
6e17df80ab
commit
19b17354e0
@ -1,11 +1,29 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
c := make(chan int, 2)
|
||||
c <- 1
|
||||
c <- 2
|
||||
fmt.Println(<-c)
|
||||
fmt.Println(<-c)
|
||||
q := make(chan bool)
|
||||
|
||||
go func(c chan int) {
|
||||
for i := range c {
|
||||
fmt.Println("\t", i, "<- popped")
|
||||
time.Sleep(300 * time.Millisecond)
|
||||
}
|
||||
}(c)
|
||||
|
||||
go func(c chan int) {
|
||||
i := 0
|
||||
for {
|
||||
c <- i
|
||||
fmt.Println("pushed ->", i)
|
||||
i += 1
|
||||
}
|
||||
}(c)
|
||||
|
||||
<-q
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user