1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2024-12-04 09:43:23 +02:00

Replace Ticker with Timer since Ticker does not Reset yet

This commit is contained in:
Vladimir Mihailenco 2020-05-14 14:02:04 +03:00
parent 2719c0ac16
commit 891d16dd15

View File

@ -158,12 +158,17 @@ func WithBlocking() BatchSpanProcessorOption {
// is shut down. It calls the exporter in batches of up to MaxExportBatchSize
// waiting up to ScheduledDelayMillis to form a batch.
func (bsp *BatchSpanProcessor) processQueue() {
ticker := time.NewTicker(bsp.o.ScheduledDelayMillis)
defer ticker.Stop()
timer := time.NewTimer(bsp.o.ScheduledDelayMillis)
defer timer.Stop()
batch := make([]*export.SpanData, 0, bsp.o.MaxExportBatchSize)
exportSpans := func() {
if !timer.Stop() {
<-timer.C
}
timer.Reset(bsp.o.ScheduledDelayMillis)
if len(batch) > 0 {
bsp.e.ExportSpans(context.Background(), batch)
batch = batch[:0]
@ -175,13 +180,12 @@ loop:
select {
case <-bsp.stopCh:
break loop
case <-ticker.C:
case <-timer.C:
exportSpans()
case sd := <-bsp.queue:
if sd.SpanContext.IsSampled() {
batch = append(batch, sd)
if len(batch) == bsp.o.MaxExportBatchSize {
ticker.Reset(bsp.o.ScheduledDelayMillis)
exportSpans()
}
}