in appinsights/inmemorychannel.go [214:267]
func (state *inMemoryChannelState) waitToSend() bool {
// Things that are used by the sender if we receive a control message
state.retryTimeout = 0
state.retry = true
state.callback = nil
// Delay until timeout passes or buffer fills up
state.timer.Reset(state.channel.batchInterval)
for {
if len(state.buffer) >= state.channel.batchSize {
if !state.timer.Stop() {
<-state.timer.C()
}
return state.send()
}
select {
case event := <-state.channel.collectChan:
if event == nil {
// Channel closed? Not intercepted by Send()?
panic("Received nil event")
}
state.buffer = append(state.buffer, event)
case ctl := <-state.channel.controlChan:
if ctl.stop {
state.stopping = true
state.retry = ctl.retry
if !ctl.flush {
// No flush? Just exit.
state.channel.signalWhenDone(ctl.callback)
return false
}
}
if ctl.flush {
if !state.timer.Stop() {
<-state.timer.C()
}
state.retryTimeout = ctl.timeout
state.callback = ctl.callback
return state.send()
}
case <-state.timer.C():
// Timeout expired
return state.send()
}
}
}