task

package
v0.24.2 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2021 License: MIT Imports: 4 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

Overview

Package task provides a work pool, for doing many things concurrently.

Index

Constants

This section is empty.

Variables

View Source
var ErrPoolBusy = errors.New("task: work not done, pool not free in time")

Functions

This section is empty.

Types

type Task

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

Task provides a pool of goroutines for Worker tasks to be submitted.

func New

func New(poolSize int) *Task

New creates a new work pool.

func (*Task) Completed

func (t *Task) Completed() uint64

Completed returns the number of completed work items.

func (*Task) Do

func (t *Task) Do(ctx context.Context, w Worker) error

Do submits work to the pool. An error is returned in the case the pool is saturated with existing work and does not respond before the context is canceled.

func (*Task) Shutdown

func (t *Task) Shutdown()

Shutdown waits for all the goroutines to shutdown.

func (*Task) Submitted

func (t *Task) Submitted() uint64

Submitted returns the number of submitted work items.

type Worker

type Worker interface {
	Work()
}

Worker defines the single method necessary to do work in the pool.

type WorkerFunc

type WorkerFunc func()

WorkerFunc is an adapter to allow the use of ordinary functions as Workers. If f is a function with an appropriate signature, WorkerFunc is a Worker which calls f.

func (WorkerFunc) Work

func (w WorkerFunc) Work()

Work calls WorkerFunc w().

Jump to

Keyboard shortcuts

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