diff --git a/README.md b/README.md index d3ade41..2fdb9c6 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,76 @@ -# batcher -Library Implementation for Batch Processing +# Batcher +Library Implementation for Batch Processing in GO. + +## Installation +```` +go get github.com/anjulapaulus/batcher +```` + +## Implementation + +Single Insert + +```` +import ( + "fmt" + "github.com/anjulapaulus/batcher" + "log" + "time" +) + + + +func main() { + b, err := batcher.NewBatcher(1000, 5*time.Millisecond, doBatch) + if err != nil { + log.Fatal(err) + } + go func() { + for i := 1; i <= 1000; i++ { + b.Insert(i) + } + }() + + fmt.Println("Stopping") + time.Sleep(time.Second * 60) +} + +func doBatch(datas []interface{}) bool { + + for _, data := range datas { + if parsedValue, ok := data.(int); ok { + log.Println(fmt.Sprintf("[data]: %d", parsedValue)) + } + } + return true +} +```` + +Bulk Insert + +```` +func main() { + arr:=[]interface{}{1,2,3} + b, err := batcher.NewBatcher(1000, 5*time.Millisecond, doBatch) + if err != nil { + log.Fatal(err) + } + go func() { + b.InsertItems(arr) + }() + + fmt.Println("Stopping") + time.Sleep(time.Second * 5) +} + +func doBatch(datas []interface{}) bool { + + for _, data := range datas { + if parsedValue, ok := data.(int); ok { + log.Println(fmt.Sprintf("[data]: %d", parsedValue)) + } + } + return true +} + +```` \ No newline at end of file diff --git a/batcher_test.go b/batcher_test.go index b440a6f..08c6a70 100644 --- a/batcher_test.go +++ b/batcher_test.go @@ -68,20 +68,6 @@ func TestNewBatcher(t *testing.T) { } -func BenchmarkNewBatcher(b *testing.B) { - ba := batch{ - size: 1, - waitTime: 15*time.Second, - numWorkers: 1, - funct: DummyBatchFn1, - } - for i :=0; i