MCPcopy
hub / github.com/uber-go/zap / NewTicker

Method NewTicker

internal/ztest/clock.go:68–89  ·  view source on GitHub ↗

NewTicker returns a time.Ticker that ticks at the specified frequency. As with [time.NewTicker], the ticker will drop ticks if the receiver is slow, and the channel is never closed. Calling Stop on the returned ticker is a no-op. The ticker only runs when the clock is advanced.

(d time.Duration)

Source from the content-addressed store, hash-verified

66// Calling Stop on the returned ticker is a no-op.
67// The ticker only runs when the clock is advanced.
68func (c *MockClock) NewTicker(d time.Duration) *time.Ticker {
69 ch := make(chan time.Time, 1)
70
71 var tick func(time.Time)
72 tick = func(now time.Time) {
73 next := now.Add(d)
74 c.runAt(next, func() {
75 defer tick(next)
76
77 select {
78 case ch <- next:
79 // ok
80 default:
81 // The receiver is slow.
82 // Drop the tick and continue.
83 }
84 })
85 }
86 tick(c.Now())
87
88 return &time.Ticker{C: ch}
89}
90
91// runAt schedules the given function to be run at the given time.
92// The function runs without a lock held, so it may schedule more work.

Callers 3

TestSamplerConcurrentFunction · 0.95
TestMockClock_NewTickerFunction · 0.95

Calls 3

runAtMethod · 0.95
NowMethod · 0.95
AddMethod · 0.45

Tested by 3

TestSamplerConcurrentFunction · 0.76
TestMockClock_NewTickerFunction · 0.76