func (h *MultiLineHandler) run() {
	flushTimer := time.NewTimer(h.flushTimeout)
	defer func() {
		flushTimer.Stop()
		// make sure the content stored in the buffer gets sent,
		// this can happen when the stop is called in between two timer ticks.
		h.sendBuffer()
		close(h.outputChan)
	}()
	for {
		select {
		case message, isOpen := <-h.inputChan:
			if !isOpen {
				// lineChan has been closed, no more lines are expected
				return
			}
			// process the new line and restart the timeout
			if !flushTimer.Stop() {
				// timer stop doesn't not prevent the timer to tick,
				// makes sure the event is consumed to avoid sending
				// just one piece of the content.
				select {
				case <-flushTimer.C:
				default:
				}
			}
			h.process(message)
			flushTimer.Reset(h.flushTimeout)
		case <-flushTimer.C:
			// no line has been collected since a while,
			// the content is supposed to be complete.
			h.sendBuffer()
		}
	}
}
// run processes new lines from the channel and makes sur the content is properly sent when
// it stayed for too long in the buffer.
run processes new lines from the channel and makes sur the content is properly sent when
it stayed for too long in the buffer.
// run processes new lines from the channel and makes sur the content is properly sent when // it stayed for too long in the buffer .
func (h *MultiLineHandler) run() {
	flushTimer := time.NewTimer(h.flushTimeout)
	defer func() {
		flushTimer.Stop()
		h.sendBuffer()
		close(h.outputChan)
	}()
	for {
		select {
		case message, isOpen := <-h.inputChan:
			if !isOpen {
				return
			}
			if !flushTimer.Stop() {
				select {
				case <-flushTimer.C:
				default:
				}
			}
			h.process(message)
			flushTimer.Reset(h.flushTimeout)
		case <-flushTimer.C:
			h.sendBuffer()
		}
	}
}
func ( h * MultiLineHandler ) run ( ) { flushTimer := time . NewTimer ( h . flushTimeout ) defer func ( ) { flushTimer . Stop ( ) h . sendBuffer ( ) close ( h . outputChan ) } ( ) for { select { case message , isOpen := <- h . inputChan : if ! isOpen { return } if ! flushTimer . Stop ( ) { select { case <- flushTimer . C : default : } } h . process ( message ) flushTimer . Reset ( h . flushTimeout ) case <- flushTimer . C : h . sendBuffer ( ) } } }
run processes new lines from the channel and makes sur the content is properly sent when
it stayed for too long in the buffer.
run processes new lines from the channel and makes sur the content is properly sent when it stayed for too long in the buffer .
// make sure the content stored in the buffer gets sent, // this can happen when the stop is called in between two timer ticks. // lineChan has been closed, no more lines are expected // process the new line and restart the timeout // timer stop doesn't not prevent the timer to tick, // makes sure the event is consumed to avoid sending // just one piece of the content. // no line has been collected since a while, // the content is supposed to be complete.