Debian Codegraph @

batcher/README.md

raw
1 batcher
2 =======
3
4 [![Golang CI](https://github.com/eapache/go-resiliency/actions/workflows/golang-ci.yml/badge.svg)](https://github.com/eapache/go-resiliency/actions/workflows/golang-ci.yml)
5 [![GoDoc](https://godoc.org/github.com/eapache/go-resiliency/batcher?status.svg)](https://godoc.org/github.com/eapache/go-resiliency/batcher)
6 [![Code of Conduct](https://img.shields.io/badge/code%20of%20conduct-active-blue.svg)](https://eapache.github.io/conduct.html)
7
8 The batching resiliency pattern for golang.
9
10 Creating a batcher takes two parameters:
11 - the timeout to wait while collecting a batch
12 - the function to run once a batch has been collected
13
14 You can also optionally set a prefilter to fail queries before they enter the
15 batch.
16
17 ```go
18 b := batcher.New(10*time.Millisecond, func(params []interface{}) error {
19 // do something with the batch of parameters
20 return nil
21 })
22
23 b.Prefilter(func(param interface{}) error {
24 // do some sort of sanity check on the parameter, and return an error if it fails
25 return nil
26 })
27
28 for i := 0; i < 10; i++ {
29 go b.Run(i)
30 }
31 ```