ants: github.com/panjf2000/ants Index | Files | Directories

package ants

import "github.com/panjf2000/ants"

Index

Package Files

ants.go options.go pool.go pool_func.go worker.go worker_array.go worker_func.go worker_loop_queue.go worker_stack.go

Constants

❖
const (
    // DefaultAntsPoolSize is the default capacity for a default goroutine pool.
    DefaultAntsPoolSize = math.MaxInt32

    // DefaultCleanIntervalTime is the interval time to clean up goroutines.
    DefaultCleanIntervalTime = time.Second
)
❖
const (
    // OPENED represents that the pool is opened.
    OPENED = iota

    // CLOSED represents that the pool is closed.
    CLOSED
)

Variables

❖
var (

    // ErrInvalidPoolSize will be returned when setting a negative number as pool capacity, this error will be only used
    // by pool with func because pool without func can be infinite by setting up a negative capacity.
    ErrInvalidPoolSize = errors.New("invalid size for pool")

    // ErrLackPoolFunc will be returned when invokers don't provide function for pool.
    ErrLackPoolFunc = errors.New("must provide function for pool")

    // ErrInvalidPoolExpiry will be returned when setting a negative number as the periodic duration to purge goroutines.
    ErrInvalidPoolExpiry = errors.New("invalid expiry for pool")

    // ErrPoolClosed will be returned when submitting task to a closed pool.
    ErrPoolClosed = errors.New("this pool has been closed")

    // ErrPoolOverload will be returned when the pool is full and no workers available.
    ErrPoolOverload = errors.New("too many goroutines blocked on submit or Nonblocking is set")

    // ErrInvalidPreAllocSize will be returned when trying to set up a negative capacity under PreAlloc mode.
    ErrInvalidPreAllocSize = errors.New("can not set up a negative capacity under PreAlloc mode")
)

func Cap Uses

❖
func Cap() int

Cap returns the capacity of this default pool.

func Free Uses

❖
func Free() int

Free returns the available goroutines to work.

func Reboot Uses

❖
func Reboot()

Reboot reboots the default pool.

func Release Uses

❖
func Release()

Release Closes the default pool.

func Running Uses

❖
func Running() int

Running returns the number of the currently running goroutines.

func Submit Uses

❖
func Submit(task func()) error

Submit submits a task to pool.

type Logger Uses

❖
type Logger interface {
    // Printf must have the same semantics as log.Printf.
    Printf(format string, args ...interface{})
}

Logger is used for logging formatted messages.

type Option Uses

❖
type Option func(opts *Options)

Option represents the optional function.

func WithExpiryDuration Uses

❖
func WithExpiryDuration(expiryDuration time.Duration) Option

WithExpiryDuration sets up the interval time of cleaning up goroutines.

func WithLogger Uses

❖
func WithLogger(logger Logger) Option

WithLogger sets up a customized logger.

func WithMaxBlockingTasks Uses

❖
func WithMaxBlockingTasks(maxBlockingTasks int) Option

WithMaxBlockingTasks sets up the maximum number of goroutines that are blocked when it reaches the capacity of pool.

func WithNonblocking Uses

❖
func WithNonblocking(nonblocking bool) Option

WithNonblocking indicates that pool will return nil when there is no available workers.

func WithOptions Uses

❖
func WithOptions(options Options) Option

WithOptions accepts the whole options config.

func WithPanicHandler Uses

❖
func WithPanicHandler(panicHandler func(interface{})) Option

WithPanicHandler sets up panic handler.

func WithPreAlloc Uses

❖
func WithPreAlloc(preAlloc bool) Option

WithPreAlloc indicates whether it should malloc for workers.

type Options Uses

❖
type Options struct {
    // ExpiryDuration sets the expired time of every worker.
    ExpiryDuration time.Duration

    // PreAlloc indicates whether to make memory pre-allocation when initializing Pool.
    PreAlloc bool

    // Max number of goroutine blocking on pool.Submit.
    // 0 (default value) means no such limit.
    MaxBlockingTasks int

    // When Nonblocking is true, Pool.Submit will never be blocked.
    // ErrPoolOverload will be returned when Pool.Submit cannot be done at once.
    // When Nonblocking is true, MaxBlockingTasks is inoperative.
    Nonblocking bool

    // PanicHandler is used to handle panics from each worker goroutine.
    // if nil, panics will be thrown out again from worker goroutines.
    PanicHandler func(interface{})

    // Logger is the customized logger for logging info, if it is not set,
    // default standard logger from log package is used.
    Logger Logger
}

Options contains all options which will be applied when instantiating a ants pool.

type Pool Uses

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

Pool accepts the tasks from client, it limits the total of goroutines to a given number by recycling goroutines.

func NewPool Uses

❖
func NewPool(size int, options ...Option) (*Pool, error)

NewPool generates an instance of ants pool.

func (*Pool) Cap Uses

❖
func (p *Pool) Cap() int

Cap returns the capacity of this pool.

func (*Pool) Free Uses

❖
func (p *Pool) Free() int

Free returns the available goroutines to work.

func (*Pool) Reboot Uses

❖
func (p *Pool) Reboot()

Reboot reboots a released pool.

func (*Pool) Release Uses

❖
func (p *Pool) Release()

Release Closes this pool.

func (*Pool) Running Uses

❖
func (p *Pool) Running() int

Running returns the number of the currently running goroutines.

func (*Pool) Submit Uses

❖
func (p *Pool) Submit(task func()) error

Submit submits a task to this pool.

func (*Pool) Tune Uses

❖
func (p *Pool) Tune(size int)

Tune changes the capacity of this pool, this method is noneffective to the infinite pool.

type PoolWithFunc Uses

❖
type PoolWithFunc struct {
    // contains filtered or unexported fields
}

PoolWithFunc accepts the tasks from client, it limits the total of goroutines to a given number by recycling goroutines.

func NewPoolWithFunc Uses

❖
func NewPoolWithFunc(size int, pf func(interface{}), options ...Option) (*PoolWithFunc, error)

NewPoolWithFunc generates an instance of ants pool with a specific function.

func (*PoolWithFunc) Cap Uses

❖
func (p *PoolWithFunc) Cap() int

Cap returns the capacity of this pool.

func (*PoolWithFunc) Free Uses

❖
func (p *PoolWithFunc) Free() int

Free returns a available goroutines to work.

func (*PoolWithFunc) Invoke Uses

❖
func (p *PoolWithFunc) Invoke(args interface{}) error

Invoke submits a task to pool.

func (*PoolWithFunc) Reboot Uses

❖
func (p *PoolWithFunc) Reboot()

Reboot reboots a released pool.

func (*PoolWithFunc) Release Uses

❖
func (p *PoolWithFunc) Release()

Release Closes this pool.

func (*PoolWithFunc) Running Uses

❖
func (p *PoolWithFunc) Running() int

Running returns the number of the currently running goroutines.

func (*PoolWithFunc) Tune Uses

❖
func (p *PoolWithFunc) Tune(size int)

Tune changes the capacity of this pool.

Directories

PathSynopsis
examples
internal

Package ants imports 9 packages (graph) and is imported by 14 packages. Updated 2020-07-06. Refresh now. Tools for package owners.