Documentation ¶
Overview ¶
Package batch provides support for batching up singular calls into multiple-value calls which may be more efficient.
Eventually, this could potentially live in x/sync alongside the singleflight package.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Caller ¶
type Caller[Value, Result any] struct { // contains filtered or unexported fields }
Caller represents a batch caller. It accumulates multiple calls into a single "batch" call to reduce the total number of calls made. The zero value is equivalent to NewCaller(0, 0).
func NewCaller ¶
func NewCaller[Value, Result any](maxConcurrency int, initialDelay time.Duration) *Caller[Value, Result]
NewCaller returns a Caller that issues a maximum of maxConcurrency concurrent calls, and delays for at least initialDelay after issuing a call to accumulate possible extra calls to avoid the first call being issued immediately.
If maxConcurrency is non-positive, 1 concurrent call will be allowed.
func (*Caller[V, R]) Do ¶
Do does the equivalent of:
rs, err := call(v) if err != nil { return _, err } return rs[0], nil
except that only a limited number of Do methods can be excecuting at a time. If the maximum count has been reached, additional Do calls will accumulate argument values into a slice and use the same call function, which should return a slice with the results in corresponding elements to the arguments.