gopool

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2021 License: Apache-2.0 Imports: 5 Imported by: 4

Documentation

Index

Constants

View Source
const (
	DefaultWorkers     = 1000
	DefaultIdleTimeout = 60 * time.Second
)

Variables

View Source
var GlobalConfig = Configure()

Functions

func CloseAndWait

func CloseAndWait()

func Go

func Go(f func(context.Context))

func Init

func Init(cfg *Config)

Types

type Config

type Config struct {
	Ctx         context.Context
	Concurrent  int
	IdleTimeout time.Duration
	// RecoverFunc execute after recover a panic
	RecoverFunc func(r interface{})
}

func Configure

func Configure() *Config

func (*Config) Idle

func (c *Config) Idle(time time.Duration) *Config

func (*Config) WithContext

func (c *Config) WithContext(ctx context.Context) *Config

func (*Config) WithRecoverFunc

func (c *Config) WithRecoverFunc(f func(r interface{})) *Config

func (*Config) Workers

func (c *Config) Workers(max int) *Config

type Pool

type Pool struct {
	Cfg *Config
	// contains filtered or unexported fields
}

func New

func New(cfgs ...*Config) *Pool

func (*Pool) Close

func (g *Pool) Close(grace bool)

Close will call context.Cancel(), so all goroutines maybe exit when job does not complete

func (*Pool) Do

func (g *Pool) Do(f func(context.Context)) *Pool

Do pick one idle goroutine to do the f once

func (*Pool) Done

func (g *Pool) Done()

Done will wait for all goroutines complete the jobs and then close the pool

Jump to

Keyboard shortcuts

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