Simplified behavior of a zero capacity buffer
This commit is contained in:
parent
27928aae1d
commit
434f980a91
11
buffer.go
11
buffer.go
|
@ -30,7 +30,9 @@ func NewBuffer(capacity int, fn func(series []*influxdb.Series)) *Buffer {
|
||||||
series: make(map[string]*influxdb.Series),
|
series: make(map[string]*influxdb.Series),
|
||||||
capacity: capacity,
|
capacity: capacity,
|
||||||
}
|
}
|
||||||
|
if b.capacity > 0 {
|
||||||
go b.aggregate()
|
go b.aggregate()
|
||||||
|
}
|
||||||
|
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
@ -43,6 +45,11 @@ func (b *Buffer) Size() int {
|
||||||
|
|
||||||
// Adds one or multiple series to buffer
|
// Adds one or multiple series to buffer
|
||||||
func (b *Buffer) Add(series ...*influxdb.Series) {
|
func (b *Buffer) Add(series ...*influxdb.Series) {
|
||||||
|
if b.capacity == 0 {
|
||||||
|
b.fn(series)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
for _, item := range series {
|
for _, item := range series {
|
||||||
b.in <- item
|
b.in <- item
|
||||||
}
|
}
|
||||||
|
@ -55,6 +62,10 @@ func (b *Buffer) Flush() {
|
||||||
sbuffer = append(sbuffer, item)
|
sbuffer = append(sbuffer, item)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(sbuffer) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
go b.fn(sbuffer)
|
go b.fn(sbuffer)
|
||||||
b.Clear()
|
b.Clear()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue