Event queue processes and filling race.

We send the slice off to be process, but potentially start overwriting
the previous content straight away. Just start again with a fresh slice.

Fixes #247

Signed-off-by: Tristan Colgate <tristan@qubit.com>
This commit is contained in:
Tristan Colgate 2019-07-25 13:14:02 +01:00
parent e60f2f147b
commit 49296e321e

View file

@ -82,6 +82,7 @@ func newEventQueue(c chan Events, flushThreshold int, flushInterval time.Duratio
c: c,
flushThreshold: flushThreshold,
flushTicker: ticker,
q: make([]Event, 0, flushThreshold),
}
go func() {
for {
@ -112,7 +113,7 @@ func (eq *eventQueue) flush() {
func (eq *eventQueue) flushUnlocked() {
eq.c <- eq.q
eq.q = eq.q[:0]
eq.q = make([]Event, 0, cap(eq.q))
eventsFlushed.Inc()
}