diff --git a/timer.go b/timer.go index d6ec4c6..aa7e895 100644 --- a/timer.go +++ b/timer.go @@ -125,8 +125,8 @@ func (NilTimer) Stop() {} // Sum is a no-op. func (NilTimer) Sum() int64 { return 0 } -// Time is a no-op. -func (NilTimer) Time(func()) {} +// Time guarantees execution of the given function, but is otherwise a no-op. +func (NilTimer) Time(f func()) { f() } // Update is a no-op. func (NilTimer) Update(time.Duration) {} diff --git a/timer_test.go b/timer_test.go index f85c9b8..98bdde2 100644 --- a/timer_test.go +++ b/timer_test.go @@ -23,6 +23,15 @@ func TestGetOrRegisterTimer(t *testing.T) { } } +func TestNilTimerFunc(t *testing.T) { + tm := NilTimer{} + b := false + tm.Time(func() { b = true }) + if !b { + t.Errorf("tm.Time(func()) did not execute argument") + } +} + func TestTimerExtremes(t *testing.T) { tm := NewTimer() tm.Update(math.MaxInt64)