// clearSessionTimer is used to clear the session time for
// a single session. This is used when a session is destroyed
// explicitly and no longer needed.
548771
func (s *Server) clearSessionTimer(id string) error {
	s.sessionTimers.Stop(id)
	return nil
}
231883
func (a *Account) setExpirationTimer(d time.Duration) {
	a.etmr = time.AfterFunc(d, a.expiredTimeout)
}
974323
func deadlineTimer(t time.Time) *time.Timer {
	if t.IsZero() {
		return nil
	}
	return time.NewTimer(t.Sub(time.Now()))
}
158527
func (c *client) setPingTimer() {
	if c.srv == nil {
		return
	}
	d := c.srv.getOpts().PingInterval
	c.ping.tmr = time.AfterFunc(d, c.processPingTimer)
}
512789
func timerReset(t *time.Timer, d time.Duration) {
	if !t.Stop() {
		<-t.C
	}
	t.Reset(d)
}
455493
func (m TaskManager) HandleTimer(c context.Context, ctl task.Controller, name string, payload []byte) error {
	return nil
}
656126
func ClearSession(config *Config, timeout time.Duration) error {
	// copy config
	newConfig := *config
	newConfig.CleanSession = true

	// create client
	client := New()

	// connect to broker
	future, err := client.Connect(&newConfig)
	if err != nil {
		return err
	}

	// wait for future
	err = future.Wait(timeout)
	if err != nil {
		return err
	}

	// disconnect
	err = client.Disconnect()
	if err != nil {
		return err
	}

	return nil
}
311305
func (c *RollingCounter) cleanup() {
	now := c.clock.UtcNow()
	for i := 0; i < len(c.values); i++ {
		now = now.Add(time.Duration(-1*i) * c.resolution)
		if now.Truncate(c.resolution).After(c.lastUpdated.Truncate(c.resolution)) {
			c.values[c.getBucket(now)] = 0
		} else {
			break
		}
	}
}
692589
func finalizer() lazyref.Finalizer {
	return func(v interface{}) {
		if handle, ok := v.(*ContextHandle); ok {
			err := handle.ctx.CloseAllSessions(handle.slot)
			if err != nil {
				logger.Warnf("unable to close all sessions in finalizer for [%s, %s] : %s", handle.lib, handle.label, err)
			}
			err = handle.ctx.Finalize()
			if err != nil {
				logger.Warnf("unable to finalize pkcs11 ctx in finalizer for [%s, %s] : %s", handle.lib, handle.label, err)
			}
			handle.ctx.Destroy()
			cachebridge.ClearAllSession()
		}
	}
}
964616
func newUnstartedTimer() *time.Timer {
	timer := time.NewTimer(time.Second)
	timer.Stop()
	return timer
}
529453
func NewTimer() *Timer {
	return &Timer{t: time.NewTimer(time.Duration(math.MaxInt64))}
}
537826
func NewTimeDecider(timesource timesrc.TimeSource, remainingTimeThreshold time.Duration) oracle.OracleSource {
	return &timedecider{timesource, remainingTimeThreshold}
}
1222371
func (t *FakeTimer) Reset(d time.Duration) bool {
	t.time = t.clock.now.Add(d)

	// Empty the channel if already filled.
	select {
	case <-t.c:
	default:
	}

	if t.index >= 0 {
		heap.Fix(&t.clock.timers, t.index)
		return true
	}
	heap.Push(&t.clock.timers, t)
	return false
}
377256
func (gc *GenericChannelAspect) StartTimer(d time.Duration) {
	timer := time.Tick(d)
	go func() {
		for {
			<-timer
			gc.calculate()
		}
	}()
}
214280
func (s *inMemStore) sessCleaner(interval time.Duration) {
	ticker := time.NewTicker(interval)

	for {
		select {
		case <-s.closeTicker:
			// We are being shut down...
			ticker.Stop()
			return
		case now := <-ticker.C:
			// Do a sweep.
			// Remove is very rare compared to the number of checks, so:
			// "Quick" check with read-lock to see if there's anything to remove:
			// Note: Session.Access() is called with s.mux, the same mutex we use
			// when looking for timed-out sessions, so we're good.
			needRemove := func() bool {
				s.mux.RLock() // Read lock is enough
				defer s.mux.RUnlock()

				for _, sess := range s.sessions {
					if now.Sub(sess.Accessed()) > sess.Timeout() {
						return true
					}
				}
				return false
			}()
			if !needRemove {
				continue
			}

			// Remove required:
			func() {
				s.mux.Lock() // Read-write lock required
				defer s.mux.Unlock()

				for _, sess := range s.sessions {
					if now.Sub(sess.Accessed()) > sess.Timeout() {
						s.logPrintln("Session timed out:", sess.ID())
						delete(s.sessions, sess.ID())
					}
				}
			}()
		}
	}
}
301588
func (e *eventTimestamper) Reset() {
	e.lock.Lock()
	e.timestamp = time.Now()
	e.lock.Unlock()
}
1158287
func AddTimer(d time.Duration, callback CallbackFunc) *Timer {
	if d < MIN_TIMER_INTERVAL {
		d = MIN_TIMER_INTERVAL
	}

	t := &Timer{
		fireTime: time.Now().Add(d),
		interval: d,
		callback: callback,
		repeat:   true,
	}
	timerHeapLock.Lock()
	t.addseq = nextAddSeq // set addseq when locked
	nextAddSeq += 1

	heap.Push(&timerHeap, t)
	timerHeapLock.Unlock()
	return t
}