pool

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2021 License: Apache-2.0 Imports: 1 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pool

type Pool struct {
	Tasks []*Task
	// contains filtered or unexported fields
}

Pool is a worker group that runs a number of tasks at a configured concurrency.

func NewPool

func NewPool(tasks []*Task, concurrency int) *Pool

NewPool initializes a new pool with the given tasks and at the given concurrency.

func (*Pool) Run

func (p *Pool) Run()

Run runs all work within the pool and blocks until it's finished.

type Task

type Task struct {
	// Err holds an error that occurred during a task. Its
	// result is only meaningful after Run has been called
	// for the pool that holds it.
	Err error
	// contains filtered or unexported fields
}

Task encapsulates a work item that should go in a work pool.

func MapTask

func MapTask(task func(arg TaskArg) func() error, args []TaskArg) (tasks []*Task)

func NewTask

func NewTask(f func() error) *Task

NewTask initializes a new task based on a given work function.

func (*Task) Run

func (t *Task) Run(wg *sync.WaitGroup)

Run runs a Task and does appropriate accounting via a given sync.WorkGroup.

type TaskArg

type TaskArg interface{}

Jump to

Keyboard shortcuts

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