worker pool
This commit is contained in:
parent
68bd574b90
commit
cc8b8cf7a4
1
README
1
README
@ -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
27
src/xx-worker-pool.go
Normal 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")
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user