closing channels

This commit is contained in:
Mark McGranaghan 2012-09-30 20:24:50 -07:00
parent de85f000de
commit 1f30b700bd
72 changed files with 34 additions and 1 deletions

View File

@ -0,0 +1,33 @@
package main
import "fmt"
import "time"
func main() {
jobs := make(chan bool, 5)
done := make(chan bool)
go func() {
for {
_, more := <- jobs
if more {
fmt.Println("received job")
} else {
fmt.Println("received all")
done <- true
return
}
}
}()
for i := 0; i < 5 ; i++ {
jobs <- false
fmt.Println("sent job")
}
time.Sleep(100 * time.Millisecond)
close(jobs)
fmt.Println("sent all")
<- done
}

View File

@ -44,7 +44,7 @@ scatter-gather
rate-limiting
worker-pools
nonblocking-channel-operations ~
closing-channels ~
closing-channels
timers
tickers
state-goroutine