func()

in loadgen/eventhandler/handler.go [249:280]


func (h *Handler) SendBatchesInLoop(ctx context.Context) error {
	// state is created here because the total number of events in h.batches can be smaller than the burst
	// and it can lead the sendBatches to finish its cycle without sending the desired burst number of events.
	// If we keep the state within sendBatches, it will wait for the interval t whenever starting the function as
	// `s.sent` is set to 0 so it needs to know the previous run's state

	s := state{
		burst: h.config.Limiter.Burst(),
	}

	// Send events in batches and when getting an error restart from where
	// we left.
	for {
		select {
		case <-ctx.Done():
			return ctx.Err()
		default:
			if _, err := h.sendBatches(ctx, &s); err != nil {
				if h.config.RunForever {
					h.logger.Error("failed to send batch of events", zap.Error(err))
					continue
				}
				return err
			}
			// safeguard `s.sent` so that it doesn't exceed math.MaxInt
			// but keep the remainder so the next batches know where to start
			if s.burst > 0 {
				s.sent = s.sent % s.burst
			}
		}
	}
}