Documentation ¶
Overview ¶
Package par implements parallel execution helpers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrCacheEntryNotFound = errors.New("cache entry not found")
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache[K comparable, V any] struct { // contains filtered or unexported fields }
Cache runs an action once per key and caches the result.
type ErrCache ¶ added in go1.21.0
type ErrCache[K comparable, V any] struct { Cache[K, errValue[V]] }
ErrCache is like Cache except that it also stores an error value alongside the cached value V.
type Queue ¶ added in go1.16
type Queue struct {
// contains filtered or unexported fields
}
Queue manages a set of work items to be executed in parallel. The number of active work items is limited, and excess items are queued sequentially.
func NewQueue ¶ added in go1.16
NewQueue returns a Queue that executes up to maxActive items in parallel.
maxActive must be positive.
type Work ¶
type Work[T comparable] struct { // contains filtered or unexported fields }
Work manages a set of work items to be executed in parallel, at most once each. The items in the set must all be valid map keys.
func (*Work[T]) Add ¶
func (w *Work[T]) Add(item T)
Add adds item to the work set, if it hasn't already been added.
func (*Work[T]) Do ¶
Do runs f in parallel on items from the work set, with at most n invocations of f running at a time. It returns when everything added to the work set has been processed. At least one item should have been added to the work set before calling Do (or else Do returns immediately), but it is allowed for f(item) to add new items to the set. Do should only be used once on a given Work.