项目作者: TimothyYe

项目描述 :
A lightweight Goroutine pool.
高级语言: Go
项目地址: git://github.com/TimothyYe/gpool.git
创建时间: 2019-06-17T09:41:10Z
项目社区:https://github.com/TimothyYe/gpool

开源协议:MIT License

下载


gpool

A lightweight Goroutine worker pool, modified from grpool

Example

  1. runtime.GOMAXPROCS(runtime.NumCPU())
  2. // new a Goroutine pool with 100 workers and 50 job queue
  3. pool := gpool.NewPool(100, 50)
  4. defer pool.Release()
  5. // set 10 jobs that the pool should wait
  6. pool.WaitCount(10)
  7. // submit one or more jobs to pool
  8. for i := 0; i < 10; i++ {
  9. count := i
  10. pool.JobQueue <- func() {
  11. defer pool.JobDone()
  12. fmt.Printf("Pool job: %d\n", count)
  13. }
  14. }
  15. // wait until we call JobDone for all jobs
  16. pool.WaitAll()

License

MIT License