// Tick is a convenience function for Ticker().
// It will return a ticker channel that cannot be stopped.
325576
func (m *Mock) Tick(d time.Duration) <-chan time.Time {
	return m.Ticker(d).C
}
555847
func (t *Ticker) Run() {
	// predeclare some vars
	var (
		i, pos, nameLen int
		v               byte
		n               uint64
		err             error
		inf             Info
	)
	// ticker
	for {
		select {
		case <-t.Done:
			return
		case <-t.C:
			err = t.Profiler.Reset()
			if err != nil {
				t.Errs <- err
				continue
			}
			inf.Timestamp = time.Now().UTC().UnixNano()
			for {
				t.Val = t.Val[:0]
				t.Line, err = t.ReadSlice('\n')
				if err != nil {
					if err == io.EOF {
						break
					}
					t.Errs <- &joe.ReadError{Err: err}
				}
				// first grab the key name (everything up to the ':')
				for i, v = range t.Line {
					if v == ':' {
						pos = i + 1
						break
					}
					t.Val = append(t.Val, v)
				}
				nameLen = len(t.Val)

				// skip all spaces
				for i, v = range t.Line[pos:] {
					if v != ' ' {
						pos += i
						break
					}
				}

				// grab the numbers
				for _, v = range t.Line[pos:] {
					if v == ' ' || v == '\n' {
						break
					}
					t.Val = append(t.Val, v)
				}
				// any conversion error results in 0
				n, err = helpers.ParseUint(t.Val[nameLen:])
				if err != nil {
					t.Errs <- &joe.ParseError{Info: string(t.Val[:nameLen]), Err: err}
				}

				v = t.Val[0]
				// evaluate the key
				if v == 'A' {
					if t.Val[5] == 'e' {
						if nameLen == 6 {
							inf.Active = n
							continue
						}
						if t.Val[7] == 'a' {
							inf.ActiveAnon = n
							continue
						}
						inf.ActiveFile = n
						continue
					}
					if nameLen == 9 {
						inf.AnonPages = n
						continue
					}
					inf.AnonHugePages = n
					continue
				}
				if v == 'C' {
					if nameLen == 6 {
						inf.Cached = n
						continue
					}
					if nameLen == 11 {
						inf.CommitLimit = n
						continue
					}
					inf.CommittedAS = n
					continue
				}
				if v == 'D' {
					if nameLen == 5 {
						inf.Dirty = n
						continue
					}
					if t.Val[10] == 'k' {
						inf.DirectMap4K = n
						continue
					}
					inf.DirectMap2M = n
					continue
				}
				if v == 'H' {
					if nameLen == 14 {
						if t.Val[10] == 'F' {
							inf.HugePagesFree = n
							continue
						}
						if t.Val[10] == 'R' {
							inf.HugePagesRsvd = n
							continue
						}
						inf.HugePagesSurp = n
					}
					if t.Val[1] == 'a' {
						inf.HardwareCorrupted = n
						continue
					}
					if t.Val[9] == 'i' {
						inf.HugePagesSize = n
						continue
					}
					inf.HugePagesTotal = n
					continue
				}
				if v == 'I' {
					if nameLen == 8 {
						inf.Inactive = n
						continue
					}
					if t.Val[9] == 'a' {
						inf.InactiveAnon = n
						continue
					}
					inf.InactiveFile = n
				}
				if v == 'M' {
					v = t.Val[3]
					if nameLen < 8 {
						if v == 'p' {
							inf.Mapped = n
							continue
						}
						if v == 'F' {
							inf.MemFree = n
							continue
						}
						inf.Mlocked = n
						continue
					}
					if v == 'A' {
						inf.MemAvailable = n
						continue
					}
					inf.MemTotal = n
					continue
				}
				if v == 'S' {
					v = t.Val[1]
					if v == 'w' {
						if t.Val[4] == 'C' {
							inf.SwapCached = n
							continue
						}
						if t.Val[4] == 'F' {
							inf.SwapFree = n
							continue
						}
						inf.SwapTotal = n
						continue
					}
					if v == 'h' {
						inf.Shmem = n
						continue
					}
					if v == 'l' {
						inf.Slab = n
						continue
					}
					if v == 'R' {
						inf.SReclaimable = n
						continue
					}
					inf.SUnreclaim = n
					continue
				}
				if v == 'V' {
					if t.Val[8] == 'C' {
						inf.VmallocChunk = n
						continue
					}
					if t.Val[8] == 'T' {
						inf.VmallocTotal = n
						continue
					}
					inf.VmallocUsed = n
					continue
				}
				if v == 'W' {
					if nameLen == 9 {
						inf.Writeback = n
						continue
					}
					inf.WritebackTmp = n
					continue
				}
				if v == 'B' {
					if nameLen == 6 {
						inf.Bounce = n
						continue
					}
					inf.Buffers = n
					continue
				}
				if v == 'K' {
					inf.KernelStack = n
					continue
				}
				if v == 'N' {
					inf.NFSUnstable = n
					continue
				}
				if v == 'P' {
					inf.PageTables = n
				}
				inf.Unevictable = n
			}
			t.Data <- inf
		}
	}
}
391757
func NewTicker(last time.Time, initialOffset time.Duration, c clock.Clock) *Ticker {
	t := &Ticker{
		C:         make(chan time.Time),
		clock:     c,
		last:      last,
		offset:    initialOffset,
		newOffset: make(chan time.Duration),
	}
	go t.run()
	return t
}
551533
func (t *Ticker) Stop() {
	t.tickerMux.Lock()
	defer t.tickerMux.Unlock()

	if !t.stopped && t.stopCh != nil {
		// Ticker's already created and running
		t.ticker.Stop()
		t.stopCh <- struct{}{}
	}
	t.stopped = true
}
407014
func (s Linear) TicksAtLevel(level int) interface{} {
	return linearTicker{&s, false}.TicksAtLevel(level)
}
1168583
func (ft *fakeTicker) tick() {
	tick := ft.clock.Now()
	for {
		tick = tick.Add(ft.period)
		remaining := tick.Sub(ft.clock.Now())
		if remaining <= 0 {
			// The tick should have already happened. This can happen when
			// Advance() is called on the fake clock with a duration larger
			// than this ticker's period.
			select {
			case ft.c <- tick:
			default:
			}
			continue
		}

		select {
		case <-ft.stop:
			return
		case <-ft.clock.After(remaining):
			select {
			case ft.c <- tick:
			default:
			}
		}
	}
}
934101
func (api *KrakenApi) Ticker(pairs ...string) (*TickerResponse, error) {
	resp, err := api.queryPublic("Ticker", url.Values{
		"pair": {strings.Join(pairs, ",")},
	}, &TickerResponse{})
	if err != nil {
		return nil, err
	}

	return resp.(*TickerResponse), nil
}
203000
func (t *T) Pause() {
	if t.ticker != nil {
		t.ticker.Stop()
		t.ticker = nil
	}
}
345805
func (b *Bridge) Run(ctx context.Context) {
	ticker := time.NewTicker(b.interval)
	defer ticker.Stop()
	for {
		select {
		case <-ticker.C:
			if err := b.Push(); err != nil && b.logger != nil {
				b.logger.Println("error pushing to Graphite:", err)
			}
		case <-ctx.Done():
			return
		}
	}
}
335529
func (m *Mock) Ticker(d time.Duration) *Ticker {
	m.mu.Lock()
	defer m.mu.Unlock()
	ch := make(chan time.Time, 1)
	t := &Ticker{
		C:    ch,
		c:    ch,
		mock: m,
		d:    d,
		next: m.now.Add(d),
	}
	m.timers = append(m.timers, (*internalTicker)(t))
	return t
}
1235432
func (manager *Manager) tick(now time.Time, blocks blocks) {
	manager.config.Logger.Tracef("[%s] tick at %v, running expiry checks\n", manager.logContext, now)
	// If we need to expire leases we should do it, otherwise this
	// is just an opportunity to check for blocks that need to be
	// notified.
	if !manager.config.Store.Autoexpire() {
		manager.wg.Add(1)
		go manager.retryingExpire(now)
		// We wait for manager.retryingExpire to finish before we checkBlocks
	} else {
		manager.checkBlocks(blocks)
	}
}
1315449
func (a *Agent) flush(
	ctx context.Context,
	output *models.RunningOutput,
	interval time.Duration,
	jitter time.Duration,
) {
	// since we are watching two channels we need a ticker with the jitter
	// integrated.
	ticker := NewTicker(interval, jitter)
	defer ticker.Stop()

	logError := func(err error) {
		if err != nil {
			log.Printf("E! [agent] Error writing to output [%s]: %v", output.Name, err)
		}
	}

	for {
		// Favor shutdown over other methods.
		select {
		case <-ctx.Done():
			logError(a.flushOnce(output, interval, output.Write))
			return
		default:
		}

		select {
		case <-ticker.C:
			logError(a.flushOnce(output, interval, output.Write))
		case <-output.BatchReady:
			// Favor the ticker over batch ready
			select {
			case <-ticker.C:
				logError(a.flushOnce(output, interval, output.Write))
			default:
				logError(a.flushOnce(output, interval, output.WriteBatch))
			}
		case <-ctx.Done():
			logError(a.flushOnce(output, interval, output.Write))
			return
		}
	}
}
424620
func (eng *Engine) tick() {
	// Proton wants millisecond monotonic time
	now := int64(elapsed() / time.Millisecond)
	next := eng.Transport().Tick(now)
	if next != 0 {
		eng.timer.Reset(time.Duration((next - now) * int64(time.Millisecond)))
	}
}
880045
func (w *Writer) Start() {
	if w.ticker == nil {
		w.ticker = time.NewTicker(w.RefreshInterval)
		w.tdone = make(chan bool, 1)
	}

	go w.Listen()
}
1005580
func newTicker(nextInterval durationSeries) *ticker {
	c := make(chan time.Time)
	ticker := &ticker{
		stopChan:     make(chan struct{}),
		C:            c,
		nextInterval: nextInterval,
	}

	go func() {
		defer close(c)
		ticker.run(c)
	}()

	return ticker
}
1307993
func initInfluxDBTicker(ctx context.Context, config *types.InfluxDB) *time.Ticker {
	pushInterval, err := time.ParseDuration(config.PushInterval)
	if err != nil {
		log.FromContext(ctx).Warnf("Unable to parse %s from config.PushInterval: using 10s as the default value", config.PushInterval)
		pushInterval = 10 * time.Second
	}

	report := time.NewTicker(pushInterval)

	safe.Go(func() {
		var buf bytes.Buffer
		influxDBClient.WriteLoop(report.C, &influxDBWriter{buf: buf, config: config})
	})

	return report
}
678761
func (prod *DirectProducer) TickerMessageControlLoop(onMessage func(*Message),
	interval time.Duration, onTimeOut func()) {
	prod.setState(PluginStateActive)
	prod.onMessage = onMessage
	prod.TickerControlLoop(interval, onTimeOut)
}