par

Imports

Imports #

"fmt"
"errors"
"math/rand"
"sync"
"sync/atomic"

Constants & Variables

ErrCacheEntryNotFound var #

var ErrCacheEntryNotFound = *ast.CallExpr

Structs

Cache struct #

Cache runs an action once per key and caches the result.

type Cache struct {
m sync.Map
}

ErrCache struct #

ErrCache is like Cache except that it also stores an error value alongside the cached value V.

type ErrCache struct {
*ast.IndexListExpr
}

Queue struct #

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.

type Queue struct {
maxActive int
st chan queueState
}

Work struct #

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.

type Work struct {
f func(T)
running int
mu sync.Mutex
added map[T]bool
todo []T
wait sync.Cond
waiting int
}

cacheEntry struct #

type cacheEntry struct {
done atomic.Bool
mu sync.Mutex
result V
}

errValue struct #

type errValue struct {
v V
err error
}

queueState struct #

type queueState struct {
active int
backlog []func()
idle chan struct{...}
}

Functions

Add method #

Add adds f as a work item in the queue. Add returns immediately, but the queue will be marked as non-idle until after f (and any subsequently-added work) has completed.

func (q *Queue) Add(f func())

Add method #

Add adds item to the work set, if it hasn't already been added.

func (w **ast.IndexExpr) Add(item T)

Do method #

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.

func (w **ast.IndexExpr) Do(n int, f func(item T))

Do method #

func (c **ast.IndexListExpr) Do(key K, f func() (V, error)) (V, error)

Do method #

Do calls the function f if and only if Do is being called for the first time with this key. No call to Do with a given key returns until the one call to f returns. Do returns the value returned by the one call to f.

func (c **ast.IndexListExpr) Do(key K, f func() V) V

Get method #

Get returns the cached result associated with key. It returns ErrCacheEntryNotFound if there is no such result.

func (c **ast.IndexListExpr) Get(key K) (V, error)

Get method #

Get returns the cached result associated with key and reports whether there is such a result. If the result for key is being computed, Get does not wait for the computation to finish.

func (c **ast.IndexListExpr) Get(key K) (V, bool)

Idle method #

Idle returns a channel that will be closed when q has no (active or enqueued) work outstanding.

func (q *Queue) Idle() (<-chan struct{...})

NewQueue function #

NewQueue returns a Queue that executes up to maxActive items in parallel. maxActive must be positive.

func NewQueue(maxActive int) *Queue

init method #

func (w **ast.IndexExpr) init()

runner method #

runner executes work in w until both nothing is left to do and all the runners are waiting for work. (Then all the runners return.)

func (w **ast.IndexExpr) runner()

Generated with Arrow