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.
func (*Cache[K, V]) Clear ¶
func (c *Cache[K, V]) Clear()
Clear removes all entries in the cache.
Concurrent calls to Get may return old values. Concurrent calls to Do may return old values or store results in entries that have been deleted.
TODO(jayconrod): Delete this after the package cache clearing functions in internal/load have been removed.
func (*Cache[K, V]) Delete ¶
func (c *Cache[K, V]) Delete(key K)
Delete removes an entry from the map. It is safe to call Delete for an entry that does not exist. Delete will return quickly, even if the result for a key is still being computed; the computation will finish, but the result won't be accessible through the cache.
TODO(jayconrod): Delete this after the package cache clearing functions in internal/load have been removed.
func (*Cache[K, V]) DeleteIf ¶
DeleteIf calls pred for each key in the map. If pred returns true for a key, DeleteIf removes the corresponding entry. If the result for a key is still being computed, DeleteIf will remove the entry without waiting for the computation to finish. The result won't be accessible through the cache.
TODO(jayconrod): Delete this after the package cache clearing functions in internal/load have been removed.
type ErrCache ¶ added in v0.8.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 ¶
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 ¶
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.