More goofing around with buffered channels
This commit is contained in:
parent
6e17df80ab
commit
19b17354e0
@ -1,11 +1,29 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
c := make(chan int, 2)
|
c := make(chan int, 2)
|
||||||
c <- 1
|
q := make(chan bool)
|
||||||
c <- 2
|
|
||||||
fmt.Println(<-c)
|
go func(c chan int) {
|
||||||
fmt.Println(<-c)
|
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