Skip to content

Commit e566bac

Browse files
committed
Made "NewBatch" function to maintain consistency
1 parent 6c3617b commit e566bac

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

batch.go

+6
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ type BytesSource interface {
4545

4646
type BatchHandler func([]interface{}) error
4747

48+
func NewBatch(batchSize int, pushHandler BatchHandler, flushHandler ...BatchHandler) *Batch {
49+
b := Batch{}
50+
b.Init(batchSize, pushHandler, flushHandler...)
51+
return &b
52+
}
53+
4854
func (b *Batch) Init(batchSize int, pushHandler BatchHandler, flushHandler ...BatchHandler) {
4955
b.batchPosition = 0
5056

batch_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ import (
66
"testing"
77
)
88

9+
func TestNewBatch(t *testing.T) {
10+
b1 := NewBatch(100, func(i []interface{}) error {
11+
return nil
12+
})
13+
if b1 == nil {
14+
t.Fatal("new batch is nil")
15+
}
16+
}
17+
918
func TestBatch_PushSingleItemBatch(t *testing.T) {
1019
b1 := Batch{}
1120
singleItemBatchCallCount := 0

0 commit comments

Comments
 (0)