gopool

package
v0.0.0-...-0f8ae5d Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2019 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

package gopool provides functionality for bounded parallelism with goroutines

Index

Constants

View Source
const (
	CloseGracePeriod = 5 * time.Second
)

Variables

View Source
var (
	ErrPoolClosed = errors.New("gopool is closed")
)

Functions

This section is empty.

Types

type GoPool

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

GoPool is a structure to provide bounded parallelism with goroutines.

func New

func New(size int64) *GoPool

New creates a new GoPool with the given size, where size > 0. The size indicates the maximum number of workers that can be executed in parallel at any moment.

func (*GoPool) Active

func (g *GoPool) Active() int64

Active returns the currently active workers executing in this pool.

func (*GoPool) Close

func (g *GoPool) Close() error

Close closes using GracefulStop with the default CloseGracePeriod, to conform with the io.Closer interface.

func (*GoPool) GracefulStop

func (g *GoPool) GracefulStop(ctx context.Context) error

GracefulStop closes the pool for any new work, and waits for the current functions to finish, or until the context completes.

func (*GoPool) Max

func (g *GoPool) Max() int64

Max returns the max workers executing in parallel in this pool.

func (*GoPool) Submit

func (g *GoPool) Submit(ctx context.Context, fn func()) error

Submit submits a function to be executed in the pool. If the pool has been closed, this function will return ErrPoolClosed. If the pool is active, this function will block until either of the following is true: (1) there is space in this pool to execute the function, returning nil. (2) the context has completed, resulting in a return value of ctx.Err().

Jump to

Keyboard shortcuts

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