Documentation ¶
Overview ¶
package gopool provides functionality for bounded parallelism with goroutines
Index ¶
Constants ¶
const (
CloseGracePeriod = 5 * time.Second
)
Variables ¶
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 ¶
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) Close ¶
Close closes using GracefulStop with the default CloseGracePeriod, to conform with the io.Closer interface.
func (*GoPool) GracefulStop ¶
GracefulStop closes the pool for any new work, and waits for the current functions to finish, or until the context completes.
func (*GoPool) Submit ¶
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().