Archiving a bunch of old stuff
This commit is contained in:
29
oldstuff/gotime/gotour-artifacts/buffered-channels/main.go
Normal file
29
oldstuff/gotime/gotour-artifacts/buffered-channels/main.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
c := make(chan int, 2)
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user