Documentation ¶
Overview ¶
Package batcher supports batching of items. Batching amortizes an action with with fixed costs over multiple items. For example, if an API provides an RPC that accepts a list of items as input, but clients would prefer adding items one at a time, then a Bundler can accept individual items from the client and bundle many of them into a single RPC.
The semantics of package batcher are similar to those of package
google.golang.org/api/support/bundler
except that package batcher aims to eliminate any additional latency in the processing of items. That is, batcher will ensure there is a handler running to as soon as the first item is available to be handled while also ensuring that concurrently available items get batched. In contrast, package bundler either waits for items to arrive (adding to item latency) or produces bundles of size 1.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Batcher ¶
type Batcher struct {
// contains filtered or unexported fields
}
A Batcher collects items added to it into a batch, then calls a user-provided function to handle the batch.
func New ¶
func New(itemExample interface{}, handler func(interface{}), maxBatchSize int, maxConcurrentHandlers int) *Batcher
New creates a new Batcher.
itemExample is a value of the type that will be batched. For example, if you want to create batches of *Entry, you could pass &Entry{} for itemExample. Batches will be at most maxBatchSize.
handler is a function that will be called on each bundle. If itemExample is of type T, the argument to handler is of type []T. handler may be called multiple times concurrently up to maxConcurrentHandlers.