Documentation ¶
Overview ¶
Package coalescer combines multiple requests made over a period of time into a single request
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Coalescer ¶
type Coalescer[InputType any, ResultType any] interface { // Coalesce is a function to coalesce a given input // key = only requests with this same key will be coalesced (such as volume ID) // input = input to merge with other inputs // It is NOT guaranteed all callers receive the same result (for example, if // an input fails to merge, only that caller will receive an error) Coalesce(key string, input InputType) (ResultType, error) }
Coalescer is an interface to combine multiple requests made over a period of time into a single request
When a request is received that matches an existing in-flight request, the coalescer will attempt to merge that request into the existing request pool using the provided mergeFunction
When the delay on the request expires (determined by the time the first request comes in), the merged input is passed to the execution function, and the result to all waiting callers (those that were not rejected during the merge step)
func New ¶
func New[InputType any, ResultType any](delay time.Duration, mergeFunction func(input InputType, existing InputType) (InputType, error), executeFunction func(key string, input InputType) (ResultType, error), ) Coalescer[InputType, ResultType]
New is a function to creates a new coalescer and immediately begin processing requests delay = the time to wait for other requests to coalesce before executing mergeFunction = a function to merge a new input with the existing inputs (should return an error if the new input cannot be combined with the existing inputs, otherwise return the new merged input) executeFunction = the function to call when the delay expires