worker pool
This commit is contained in:
parent
7945544a0a
commit
d07fbefb9b
@ -1,27 +0,0 @@
|
||||
package main
|
||||
|
||||
import "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 {
|
||||
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
|
||||
}
|
||||
println("all done")
|
||||
}
|
31
095-worker-pool/worker-pool.go
Normal file
31
095-worker-pool/worker-pool.go
Normal file
@ -0,0 +1,31 @@
|
||||
// ## Worker Pool
|
||||
|
||||
package main
|
||||
|
||||
import "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 {
|
||||
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
|
||||
}
|
||||
println("all done")
|
||||
}
|
||||
|
||||
// todo: broken
|
@ -1,2 +0,0 @@
|
||||
hello
|
||||
filter
|
Loading…
x
Reference in New Issue
Block a user