worker pool

This commit is contained in:
Mark McGranaghan 2012-09-19 23:35:34 -07:00
parent 68bd574b90
commit cc8b8cf7a4
2 changed files with 27 additions and 1 deletions

1
README
View File

@ -42,7 +42,6 @@ gobyexample.com signups
* web app
* serve static files
* mongo
* worker pool
* rate limiting
* time formatting
* typed json parse/unparse

27
src/xx-worker-pool.go Normal file
View File

@ -0,0 +1,27 @@
package main
import ("fmt"; "time")
func main() {
jobs := make(chan int, 100)
acks := make(chan bool, 100)
for w := 0; w < 10; w++ {
go func() {
for j := range jobs {
fmt.Println("worker", w, "processing job", j)
time.Sleep(time.Millisecond * 150)
acks <- true
}
}()
}
for j := 0; j < 100; j++ {
jobs <- j
}
for a := 0; a < 100; a++ {
<- acks
}
fmt.Println("all done")
}