Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // Version -- Current version of this package Version string = "1.0.1" )
Functions ¶
This section is empty.
Types ¶
type BatchingConfig ¶
type BatchingConfig struct { // Maximum request size of each batch. MaxBatchSize int // Maximum wait time before batch should be executed. BatchTimeout time.Duration // User defined SendF for sending a batch request. // See SendFunc for type definition of this function. SendF SendFunc }
BatchingConfig determines how batching is done in a RequestBatcher.
type RequestBatcher ¶
type RequestBatcher struct { sync.Mutex *BatchingConfig // contains filtered or unexported fields }
RequestBatcher handles receiving of new requests, and all the background asynchronous tasks to batch and send batch.
A new RequestBatcher should be created using the NewRequestBatcher function.
Expected usage pattern of the RequestBatcher involves declaring a RequestBatcher on global scope and calling SendRequestWithTimeout from multiple goroutines.
func NewRequestBatcher ¶
func NewRequestBatcher( ctx context.Context, config *BatchingConfig, ) *RequestBatcher
NewRequestBatcher creates a new RequestBatcher from a Context and a BatchingConfig.
In the typical usage pattern, a RequestBatcher should always be alive so it is safe and recommended to use the background context.
func (*RequestBatcher) SendRequestWithTimeout ¶
func (b *RequestBatcher) SendRequestWithTimeout( newRequestBody *interface{}, timeout time.Duration, ) (interface{}, error)
SendRequestWithTimeout is a method to make a single request. It manages registering the request into the batcher, and waiting on the response.
Arguments:
newRequestBody {*interface{}} -- A request body. SendF will expect a slice of objects like newRequestBody.
Returns:
interface{} -- A response body. SendF's output is expected to be a slice of objects like this. error -- Error