项目作者: 0x5010

项目描述 :
goroutine pool for easier handling and termination
高级语言: Go
项目地址: git://github.com/0x5010/gpool.git
创建时间: 2018-01-03T02:42:58Z
项目社区:https://github.com/0x5010/gpool

开源协议:MIT License

下载


This is a goroutine pool library in the Go for easier handling and termination.

LICENSE
Build Status
Go Report Card
Godoc

Installation

  1. go get github.com/0x5010/gpool

Requirements

  • Need at least go1.7 or newer.

Usage

Create and run a gpool:

  1. var fn1, fn2 func() // the function which you want to execute, anonymous functions form closures is better
  2. var fn3, fn4 func(ctx context.Context) // with context, will canceled when pool stop
  3. var limit, jobCount int // the number of goroutine and job
  4. var wait bool // whether blocking
  5. gp := gpool.New(limit, jobCount, wait)
  6. gp.AddJob(fn1)
  7. gp.AddJob(fn2)
  8. gp.AddJobWithCtx(fn3)
  9. gp.AddJobWithCtx(fn4)
  10. if wait {
  11. gp.Wait()
  12. }

termination:

  1. gp.Stop()
  2. ...