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

package ants

import "github.com/panjf2000/ants"

Index

Package Files

ants.go pool.go pool_func.go worker.go worker_func.go

Constants

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

    // DEFAULT_CLEAN_INTERVAL_TIME is the interval time to clean up goroutines.
    DEFAULT_CLEAN_INTERVAL_TIME = 1

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

Variables

var (

    // ErrInvalidPoolSize will be returned when setting a negative number as pool capacity.
    ErrInvalidPoolSize = errors.New("invalid size 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")
)

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 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 Pool Uses

type Pool struct {

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

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

func NewPool Uses

func NewPool(size int) (*Pool, error)

NewPool generates an instance of ants pool.

func NewTimingPool Uses

func NewTimingPool(size, expiry int) (*Pool, error)

NewTimingPool generates an instance of ants pool with a custom timed task.

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) Release Uses

func (p *Pool) Release() error

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.

type PoolWithFunc Uses

type PoolWithFunc struct {

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

PoolWithFunc accept 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{})) (*PoolWithFunc, error)

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

func NewTimingPoolWithFunc Uses

func NewTimingPoolWithFunc(size, expiry int, pf func(interface{})) (*PoolWithFunc, error)

NewTimingPoolWithFunc generates an instance of ants pool with a specific function and a custom timed task.

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) Release Uses

func (p *PoolWithFunc) Release() error

Release Closed 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 change the capacity of this pool.

type Worker Uses

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

Worker is the actual executor who runs the tasks, it starts a goroutine that accepts tasks and performs function calls.

type WorkerWithFunc Uses

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

WorkerWithFunc is the actual executor who runs the tasks, it starts a goroutine that accepts tasks and performs function calls.

Directories

PathSynopsis
examples

Package ants imports 7 packages (graph) and is imported by 5 packages. Updated 2019-06-16. Refresh now. Tools for package owners.