func gatherWithTimeout(
	shutdown chan struct{},
	input *models.RunningInput,
	acc telegraf.Accumulator,
	timeout time.Duration,
) {
	ticker := time.NewTicker(timeout)
	defer ticker.Stop()
	done := make(chan error)
	go func() {
		done <- input.Input.Gather(acc)
	}()

	for {
		select {
		case err := <-done:
			if err != nil {
				acc.AddError(err)
			}
			return
		case <-ticker.C:
			err := fmt.Errorf("took longer to collect than collection interval (%s)",
				timeout)
			acc.AddError(err)
			continue
		case <-shutdown:
			return
		}
	}
}
// gatherWithTimeout gathers from the given input, with the given timeout.
//   when the given timeout is reached, gatherWithTimeout logs an error message
//   but continues waiting for it to return. This is to avoid leaving behind
//   hung processes, and to prevent re-calling the same hung process over and
//   over.
gatherWithTimeout gathers from the given input, with the given timeout.
when the given timeout is reached, gatherWithTimeout logs an error message
but continues waiting for it to return. This is to avoid leaving behind
hung processes, and to prevent re-calling the same hung process over and
over.
// gatherWithTimeout gathers from the given input with the given timeout . // when the given timeout is reached gatherWithTimeout logs an error message // but continues waiting for it to return . This is to avoid leaving behind // hung processes and to prevent re - calling the same hung process over and // over .
func gatherWithTimeout(
	shutdown chan struct{},
	input *models.RunningInput,
	acc telegraf.Accumulator,
	timeout time.Duration,
) {
	ticker := time.NewTicker(timeout)
	defer ticker.Stop()
	done := make(chan error)
	go func() {
		done <- input.Input.Gather(acc)
	}()
	for {
		select {
		case err := <-done:
			if err != nil {
				acc.AddError(err)
			}
			return
		case <-ticker.C:
			err := fmt.Errorf("took longer to collect than collection interval (%s)",
				timeout)
			acc.AddError(err)
			continue
		case <-shutdown:
			return
		}
	}
}
func gatherWithTimeout ( shutdown chan struct { } , input * models . RunningInput , acc telegraf . Accumulator , timeout time . Duration , ) { ticker := time . NewTicker ( timeout ) defer ticker . Stop ( ) done := make ( chan error ) go func ( ) { done <- input . Input . Gather ( acc ) } ( ) for { select { case err := <- done : if err != nil { acc . AddError ( err ) } return case <- ticker . C : err := fmt . Errorf ( " " , timeout ) acc . AddError ( err ) continue case <- shutdown : return } } }
gatherWithTimeout gathers from the given input, with the given timeout.
gatherWithTimeout gathers from the given input with the given timeout .