pkg testing, method (*T) Deadline() (time.Time, bool)
-pkg time, method (*Ticker) Reset(Duration)
<p>
TODO
</p>
-
-<dl id="time"><dt><a href="/pkg/time/">time</a></dt>
- <dd>
- <p><!-- golang.org/issue/33184 -->
- The new method
- <a href="/pkg/time#Ticker.Reset"><code>Ticker.Reset</code></a>
- supports changing the duration of a ticker.
- </p>
- </dd>
-</dl><!-- time -->
resettimer(t, when)
}
-// modTimer modifies an existing timer.
-//go:linkname modTimer time.modTimer
-func modTimer(t *timer, when, period int64, f func(interface{}, uintptr), arg interface{}, seq uintptr) {
- modtimer(t, when, period, f, arg, seq)
-}
-
// Go runtime.
// Ready the goroutine arg.
}
// modtimer modifies an existing timer.
-// This is called by the netpoll code or time.Ticker.Reset.
+// This is called by the netpoll code.
func modtimer(t *timer, when, period int64, f func(interface{}, uintptr), arg interface{}, seq uintptr) {
if when < 0 {
when = maxWhen
func startTimer(*runtimeTimer)
func stopTimer(*runtimeTimer) bool
func resetTimer(*runtimeTimer, int64)
-func modTimer(t *runtimeTimer, when, period int64, f func(interface{}, uintptr), arg interface{}, seq uintptr)
// The Timer type represents a single event.
// When the Timer expires, the current time will be sent on C,
stopTimer(&t.r)
}
-// Reset stops a ticker and resets its period to the specified duration.
-// The next tick will arrive after the new period elapses.
-func (t *Ticker) Reset(d Duration) {
- if t.r.f == nil {
- panic("time: Reset called on uninitialized Ticker")
- }
- modTimer(&t.r, when(d), int64(d), t.r.f, t.r.arg, t.r.seq)
-}
-
// Tick is a convenience wrapper for NewTicker providing access to the ticking
// channel only. While Tick is useful for clients that have no need to shut down
// the Ticker, be aware that without a way to shut it down the underlying
for i := 0; i < 5; i++ {
ticker := NewTicker(delta)
t0 := Now()
- for i := 0; i < count/2; i++ {
- <-ticker.C
- }
- ticker.Reset(delta * 2)
- for i := count / 2; i < count; i++ {
+ for i := 0; i < count; i++ {
<-ticker.C
}
ticker.Stop()
t1 := Now()
dt := t1.Sub(t0)
- target := 3 * delta * Duration(count/2)
+ target := delta * Duration(count)
slop := target * 2 / 10
if dt < target-slop || dt > target+slop {
errs = append(errs, fmt.Sprintf("%d %s ticks took %s, expected [%s,%s]", count, delta, dt, target-slop, target+slop))
ticker.Stop()
})
}
-
-func BenchmarkTickerReset(b *testing.B) {
- benchmark(b, func(n int) {
- ticker := NewTicker(Nanosecond)
- for i := 0; i < n; i++ {
- ticker.Reset(Nanosecond * 2)
- }
- ticker.Stop()
- })
-}
-
-func BenchmarkTickerResetNaive(b *testing.B) {
- benchmark(b, func(n int) {
- ticker := NewTicker(Nanosecond)
- for i := 0; i < n; i++ {
- ticker.Stop()
- ticker = NewTicker(Nanosecond * 2)
- }
- ticker.Stop()
- })
-}