taskpool

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2024 License: Apache-2.0 Imports: 6 Imported by: 1

README

taskpool

Documentation

Index

Constants

View Source
const (
	DefaultPoolCapacity    = 10
	DefaultExpiredDuration = time.Second
)

Variables

View Source
var (
	ErrPoolIsReleased = errors.New("pool is released")
	ErrPoolIsFull     = errors.New("pool is full")
	ErrPoolIsOverload = errors.New("pool is overload")
)

Functions

func Init added in v0.0.3

func Init(capacity int, opts ...Option)

func Submit

func Submit(ctx context.Context, task func()) error

Submit 提交task

Types

type Option

type Option func(o *Options)

func WithMaxBlockingTasks

func WithMaxBlockingTasks(maxBlockingTasks int) Option

func WithNonBlocking

func WithNonBlocking() Option

type Options

type Options struct {
	ExpiredDuration  time.Duration
	MaxBlockingTasks int
	Nonblocking      bool
}

func NewOptions

func NewOptions() *Options

func (*Options) Apply

func (o *Options) Apply(opts ...Option)

type Pool

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

func NewPool

func NewPool(capacity int, opts ...Option) (*Pool, error)

func (*Pool) Cap

func (p *Pool) Cap() int

func (*Pool) IsClosed

func (p *Pool) IsClosed() bool

func (*Pool) Release

func (p *Pool) Release()

func (*Pool) Running

func (p *Pool) Running() int

func (*Pool) Submit

func (p *Pool) Submit(ctx context.Context, f func()) error

func (*Pool) Waiting

func (p *Pool) Waiting() int

Jump to

Keyboard shortcuts

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