@@ -109,8 +109,8 @@ type expirer interface {
109
109
expire (now time.Time ) (next * time.Duration )
110
110
111
111
// Get and set the expiration time.
112
- expiry () time.Time
113
- setExpiry (time.Time )
112
+ expiration () time.Time
113
+ setExpiration (time.Time )
114
114
}
115
115
116
116
// After mimics [time.After]; it waits for the given duration to elapse on the
@@ -153,17 +153,7 @@ func (fc *FakeClock) NewTicker(d time.Duration) Ticker {
153
153
if d <= 0 {
154
154
panic (errors .New ("non-positive interval for NewTicker" ))
155
155
}
156
- var ft * fakeTicker
157
- ft = & fakeTicker {
158
- firer : newFirer (),
159
- d : d ,
160
- reset : func (d time.Duration ) {
161
- fc .l .Lock ()
162
- defer fc .l .Unlock ()
163
- fc .setExpirer (ft , d )
164
- },
165
- stop : func () { fc .stop (ft ) },
166
- }
156
+ ft := newFakeTicker (fc , d )
167
157
fc .l .Lock ()
168
158
defer fc .l .Unlock ()
169
159
fc .setExpirer (ft , d )
@@ -192,7 +182,7 @@ func (fc *FakeClock) newTimer(d time.Duration, afterfunc func()) (*fakeTimer, ti
192
182
fc .l .Lock ()
193
183
defer fc .l .Unlock ()
194
184
fc .setExpirer (ft , d )
195
- return ft , ft .expiry ()
185
+ return ft , ft .expiration ()
196
186
}
197
187
198
188
// newTimerAtTime is like newTimer, but uses a time instead of a duration.
@@ -218,12 +208,12 @@ func (fc *FakeClock) Advance(d time.Duration) {
218
208
//
219
209
// We don't iterate because the callback of the waiter might register a new
220
210
// waiter, so the list of waiters might change as we execute this.
221
- for len (fc .waiters ) > 0 && ! end .Before (fc .waiters [0 ].expiry ()) {
211
+ for len (fc .waiters ) > 0 && ! end .Before (fc .waiters [0 ].expiration ()) {
222
212
w := fc .waiters [0 ]
223
213
fc .waiters = fc .waiters [1 :]
224
214
225
215
// Use the waiter's expiration as the current time for this expiration.
226
- now := w .expiry ()
216
+ now := w .expiration ()
227
217
fc .time = now
228
218
if d := w .expire (now ); d != nil {
229
219
// Set the new expiration if needed.
@@ -311,10 +301,10 @@ func (fc *FakeClock) setExpirer(e expirer, d time.Duration) {
311
301
return
312
302
}
313
303
// Add the expirer to the set of waiters and notify any blockers.
314
- e .setExpiry (fc .time .Add (d ))
304
+ e .setExpiration (fc .time .Add (d ))
315
305
fc .waiters = append (fc .waiters , e )
316
306
slices .SortFunc (fc .waiters , func (a , b expirer ) int {
317
- return a .expiry ().Compare (b .expiry ())
307
+ return a .expiration ().Compare (b .expiration ())
318
308
})
319
309
320
310
// Notify blockers of our new waiter.
@@ -327,31 +317,3 @@ func (fc *FakeClock) setExpirer(e expirer, d time.Duration) {
327
317
return false
328
318
})
329
319
}
330
-
331
- // firer is used by fakeTimer and fakeTicker used to help implement expirer.
332
- type firer struct {
333
- // The channel associated with the firer, used to send expiration times.
334
- c chan time.Time
335
-
336
- // The time when the firer expires. Only meaningful if the firer is currently
337
- // one of a fakeClock's waiters.
338
- exp time.Time
339
- }
340
-
341
- func newFirer () firer {
342
- return firer {c : make (chan time.Time , 1 )}
343
- }
344
-
345
- func (f * firer ) Chan () <- chan time.Time {
346
- return f .c
347
- }
348
-
349
- // expiry implements expirer.
350
- func (f * firer ) expiry () time.Time {
351
- return f .exp
352
- }
353
-
354
- // setExpiry implements expirer.
355
- func (f * firer ) setExpiry (t time.Time ) {
356
- f .exp = t
357
- }
0 commit comments