gf/geg/os/grpool/grpool1.go
2018-07-27 15:48:49 +08:00

30 lines
547 B
Go

package main
import (
"time"
"fmt"
"gitee.com/johng/gf/g/os/grpool"
"gitee.com/johng/gf/g/os/gtime"
)
func job() {
time.Sleep(1*time.Second)
}
func main() {
pool := grpool.New(100)
for i := 0; i < 1000; i++ {
pool.Add(job)
}
fmt.Println("worker:", pool.Size())
fmt.Println(" jobs:", pool.Jobs())
gtime.SetInterval(time.Second, func() bool {
fmt.Println("worker:", pool.Size())
fmt.Println(" jobs:", pool.Jobs())
fmt.Println()
return true
})
select {}
}