1
0
Fork 0

Simplified behavior of a zero capacity buffer

This commit is contained in:
Gregory Eremin 2014-08-23 02:12:12 +07:00
parent 27928aae1d
commit 434f980a91
1 changed files with 12 additions and 1 deletions

View File

@ -30,7 +30,9 @@ func NewBuffer(capacity int, fn func(series []*influxdb.Series)) *Buffer {
series: make(map[string]*influxdb.Series),
capacity: capacity,
}
go b.aggregate()
if b.capacity > 0 {
go b.aggregate()
}
return b
}
@ -43,6 +45,11 @@ func (b *Buffer) Size() int {
// Adds one or multiple series to buffer
func (b *Buffer) Add(series ...*influxdb.Series) {
if b.capacity == 0 {
b.fn(series)
return
}
for _, item := range series {
b.in <- item
}
@ -55,6 +62,10 @@ func (b *Buffer) Flush() {
sbuffer = append(sbuffer, item)
}
if len(sbuffer) == 0 {
return
}
go b.fn(sbuffer)
b.Clear()
}