Help us shape the future of Go! Take the 2026 Go Developer Survey

gpool

package module
v0.0.0-...-fe52a7f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 27, 2018 License: MIT Imports: 2 Imported by: 0

README

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()
...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GPool

type GPool struct {
	// contains filtered or unexported fields
}

GPool 协程池

func New

func New(limit, jobCount int, wait bool) *GPool

New 初始化协程池

func (*GPool) AddJob

func (gp *GPool) AddJob(fn func())

AddJob 添加任务

func (*GPool) AddJobWithCtx

func (gp *GPool) AddJobWithCtx(fn func(ctx context.Context))

AddJobWithCtx 添加可终止的任务

func (*GPool) Start

func (gp *GPool) Start(ctx context.Context)

Start 协程池运行

func (*GPool) Stop

func (gp *GPool) Stop()

Stop 强制终止

func (*GPool) Wait

func (gp *GPool) Wait()

Wait 等待全部任务运行完

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL