// runInputs starts and triggers the periodic gather for Inputs.
//
// When the context is done the timers are stopped and this function returns
// after all ongoing Gather calls complete.
772769
func (a *Agent) runInputs(
	ctx context.Context,
	startTime time.Time,
	dst chan<- telegraf.Metric,
) error {
	var wg sync.WaitGroup
	for _, input := range a.Config.Inputs {
		interval := a.Config.Agent.Interval.Duration
		jitter := a.Config.Agent.CollectionJitter.Duration

		// Overwrite agent interval if this plugin has its own.
		if input.Config.Interval != 0 {
			interval = input.Config.Interval
		}

		acc := NewAccumulator(input, dst)
		acc.SetPrecision(a.Precision())

		wg.Add(1)
		go func(input *models.RunningInput) {
			defer wg.Done()

			if a.Config.Agent.RoundInterval {
				err := internal.SleepContext(
					ctx, internal.AlignDuration(startTime, interval))
				if err != nil {
					return
				}
			}

			a.gatherOnInterval(ctx, acc, input, interval, jitter)
		}(input)
	}
	wg.Wait()

	return nil
}
575098
func RunIteration() {
	Time.Tick()

	if !opts.HeadlessMode {
		Input.update()
	}

	// Then update the world and all Systems
	currentUpdater.Update(Time.Delta())
}
669540
func (d *Dataset) Run(option ...FlowOption) {
	d.RunContext(context.Background(), option...)
}
914240
func (s *JobSettings) SetInputs(v []*Input) *JobSettings {
	s.Inputs = v
	return s
}
834936
func RunFunc(benchmarkFunc func() int, duration time.Duration, c int) *Result {
	workers := make([]Worker, c)
	for i := 0; i < c; i++ {
		workers[i] = &funcWorker{ID: i, benchmarkFunc: benchmarkFunc}
	}
	return Run(workers, duration)
}
1241839
func (re *runExtractor) Runs() []*platform.Run {
	runs := make([]*platform.Run, 0, len(re.runs))
	for _, r := range re.runs {
		r := r
		runs = append(runs, &r)
	}

	sort.Slice(runs, func(i, j int) bool { return runs[i].ID < runs[j].ID })
	return runs
}
197907
func (tio *Timeout) RunContext(ctx context.Context) (*ExitStatus, error) {
	if err := tio.start(); err != nil {
		return nil, err
	}
	return tio.wait(ctx), nil
}
1340749
func (s *ListInputsOutput) SetInputs(v []*Input) *ListInputsOutput {
	s.Inputs = v
	return s
}
500854
func (u *Uniter) RunCommands(args RunCommandsArgs) (results *exec.ExecResponse, err error) {
	// TODO(axw) drop this when we move the run-listener to an independent
	// worker. This exists purely for the tests.
	return u.runListener.RunCommands(args)
}
53152
func (p *InfluxLineFormatProcess) Run(reader Reader, out io.Writer, errCh chan<- error) {
	errCh <- func() (err error) {
		defer reader.Close()

		sort.Strings(p.Tags)
		sort.Strings(p.Values)
		// see: http://stackoverflow.com/questions/13340717/json-numbers-regular-expression
		numberMatcher := regexp.MustCompile("^ *-?(?:0|[1-9]\\d*)(?:\\.\\d+)?(?:[eE][+-]?\\d+)? *$")

		if location, err := time.LoadLocation(p.Location); err != nil {
			return err
		} else {

			maxLen := len(p.Measurement)
			count := 1
			for data := range reader.C() {
				count++

				stringTs := data.Get(p.Timestamp)

				parse := func(s string) (time.Time, error) {
					if p.Format == "ns" {
						if ns, err := strconv.ParseInt(s, 10, 64); err != nil {
							return time.Unix(0, 0), err
						} else {
							return time.Unix(0, ns), nil
						}
					} else if p.Format == "s" {
						if sec, err := strconv.ParseInt(s, 10, 64); err != nil {
							return time.Unix(0, 0), err
						} else {
							return time.Unix(sec, 0), nil
						}
					} else if p.Format == "ms" {
						if ms, err := strconv.ParseInt(s, 10, 64); err != nil {
							return time.Unix(0, 0), err
						} else {
							return time.Unix(0, ms*1000000), nil
						}
					} else {
						return time.ParseInLocation(p.Format, stringTs, location)
					}
				}

				if ts, err := parse(stringTs); err != nil {
					return err
				} else {

					buffer := make([]byte, 0, maxLen)
					buffer = append(buffer, p.Measurement...)
					for _, t := range p.Tags {
						v := data.Get(t)
						if v == "" {
							continue
						}
						buffer = append(buffer, ","...)
						buffer = append(buffer, t...)
						buffer = append(buffer, "="...)
						buffer = append(buffer, escapeTag([]byte(v))...)
					}

					buffer = append(buffer, " "...)
					first := true
					appended := 0
					for _, f := range p.Values {
						v := data.Get(f)
						if v == "" {
							continue
						}

						appended++
						if !first {
							buffer = append(buffer, ","...)
						} else {
							first = false
						}
						buffer = append(buffer, f...)
						buffer = append(buffer, "="...)
						if numberMatcher.MatchString(v) || v == "true" || v == "false" {
							buffer = append(buffer, v...)
						} else {
							buffer = append(buffer, strconv.Quote(v)...)
						}
					}

					if appended == 0 {
						fmt.Fprintf(os.Stderr, "%d: dropping field-less point\n", count)
						continue
					}

					if len(buffer) > maxLen {
						maxLen = len(buffer)
					}

					buffer = append(buffer, " "...)
					buffer = append(buffer, strconv.FormatInt(ts.UnixNano(), 10)...)
					buffer = append(buffer, "\n"...)

					if _, err := out.Write(buffer); err != nil {
						return err
					}
				}

			}
			return reader.Error()
		}
	}()
}
1019862
func (s *CreateJobInput) SetInputs(v []*JobInput) *CreateJobInput {
	s.Inputs = v
	return s
}
296324
func (r *REPL) loadInput(ctx context.Context, compiler *ast.Compiler) (ast.Value, error) {

	q := topdown.NewQuery(ast.MustParseBody("data.repl.input = x")).
		WithCompiler(compiler).
		WithStore(r.store).
		WithTransaction(r.txn)

	qrs, err := q.Run(ctx)
	if err != nil {
		return nil, err
	}

	if len(qrs) != 1 {
		return nil, nil
	}

	return qrs[0][ast.Var("x")].Value, nil
}
465443
func (i *instanceManager) run() {
	// Dispense once to ensure we are given a valid plugin
	if _, err := i.dispense(); err != nil {
		i.logger.Error("dispensing initial plugin failed", "error", err)
		return
	}

	// Create a waitgroup to block on shutdown for all created goroutines to
	// exit
	var wg sync.WaitGroup

	// Start the fingerprinter
	wg.Add(1)
	go func() {
		i.fingerprint()
		wg.Done()
	}()

	// Wait for a valid result before starting stats collection
	select {
	case <-i.ctx.Done():
		goto DONE
	case <-i.firstFingerprintCh:
	}

	// Start stats
	wg.Add(1)
	go func() {
		i.collectStats()
		wg.Done()
	}()

	// Do a final cleanup
DONE:
	wg.Wait()
	i.cleanup()
}
1180379
func (e *UserSummary) Run(m libkb.MetaContext) error {
	sums, err := e.get(m)
	if err != nil {
		return err
	}
	e.summaries = sums
	return nil
}
442271
func (m *RegeneratingDiscoveryRESTMapper) RunUntil(stop <-chan struct{}) {
	go wait.Until(func() {
		if err := m.RegenerateMappings(); err != nil {
			klog.Errorf("error regenerating REST mappings from discovery: %v", err)
		}
	}, m.refreshInterval, stop)
}
1324405
func (p *UnitStatePublisher) Run(beatchan <-chan *unit.UnitStateHeartbeat, stop <-chan struct{}) {
	var period time.Duration
	if p.ttl > 10*time.Second {
		period = p.ttl * 4 / 5
	} else {
		period = p.ttl / 2
	}

	go func() {
		for {
			select {
			case <-stop:
				return
			case <-p.clock.After(period):
				p.cacheMutex.Lock()
				for name, us := range p.cache {
					go p.queueForPublish(name, us)
				}
				p.pruneCache()
				p.cacheMutex.Unlock()
			}
		}
	}()

	machID := p.mach.State().ID

	// Spawn goroutines to publish unit states. Each goroutine waits until
	// it sees an event arrive on toPublish, then attempts to grab the
	// relevant UnitState and publish it to the registry.
	for i := 0; i < numPublishers; i++ {
		go func() {
			for {
				select {
				case <-stop:
					return
				case name := <-p.toPublish:
					p.toPublishMutex.Lock()
					// Grab the latest state by that name
					us, ok := p.toPublishStates[name]
					if !ok {
						// If one doesn't exist, ignore.
						p.toPublishMutex.Unlock()
						continue
					}
					delete(p.toPublishStates, name)
					p.toPublishMutex.Unlock()
					p.publisher(name, us)

				}
			}
		}()
	}

	for {
		select {
		case <-stop:
			return
		case bt := <-beatchan:
			if bt.State != nil {
				bt.State.MachineID = machID
			}

			if p.updateCache(bt) {
				go p.queueForPublish(bt.Name, bt.State)
			}
		}
	}
}
724470
func (def *Synthdef) processUgenInput(input Input, stack *stack, depth int) {
	switch v := input.(type) {
	case *Ugen:
		def.topsortr(v, stack, depth+1)
		break
	case MultiInput:
		// multi input
		mins := v.InputArray()
		for j := len(mins) - 1; j >= 0; j-- {
			switch w := mins[j].(type) {
			case *Ugen:
				def.topsortr(w, stack, depth+1)
				break
			}
		}
		break
	}
}