Skip to content
/ gpool Public

goroutine pool for easier handling and termination

License

Notifications You must be signed in to change notification settings

0x5010/gpool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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

LICENSE Build Status Go Report Card Godoc

Installation

go get github.com/0x5010/gpool

Requirements

  • Need at least go1.7 or newer.

Usage

Create and run a gpool:

var fn1, fn2 func() // the function which you want to  execute, anonymous functions form closures is better
var fn3, fn4 func(ctx context.Context) // with context, will canceled when pool stop
var limit, jobCount int   // the number of goroutine and job
var wait bool                          // whether blocking

gp := gpool.New(limit, jobCount, wait)
gp.AddJob(fn1)
gp.AddJob(fn2)
gp.AddJobWithCtx(fn3)
gp.AddJobWithCtx(fn4)

if wait {
	gp.Wait()
}

termination:

gp.Stop()
...

About

goroutine pool for easier handling and termination

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages