Browse Source

little things

pull/1842/head
Ethan Buchman 7 years ago
parent
commit
76433d9040
2 changed files with 6 additions and 7 deletions
  1. +5
    -5
      common/repeat_timer.go
  2. +1
    -2
      common/repeat_timer_test.go

+ 5
- 5
common/repeat_timer.go View File

@ -42,11 +42,11 @@ func (t *defaultTicker) Stop() {
//----------------------------------------
// LogicalTickerMaker
// Construct a TickerMaker that always uses `ch`.
// Construct a TickerMaker that always uses `source`.
// It's useful for simulating a deterministic clock.
func NewLogicalTickerMaker(ch chan time.Time) TickerMaker {
func NewLogicalTickerMaker(source chan time.Time) TickerMaker {
return func(dur time.Duration) Ticker {
return newLogicalTicker(ch, dur)
return newLogicalTicker(source, dur)
}
}
@ -66,8 +66,8 @@ func newLogicalTicker(source <-chan time.Time, interval time.Duration) Ticker {
return lt
}
// We clearly need a new goroutine, for logicalTicker may have been created
// from a goroutine separate from the source.
// We need a goroutine to read times from t.source
// and fire on t.Chan() when `interval` has passed.
func (t *logicalTicker) fireRoutine(interval time.Duration) {
source := t.source


+ 1
- 2
common/repeat_timer_test.go View File

@ -29,7 +29,6 @@ func TestRepeat(t *testing.T) {
select {
case _ = <-rt.Chan():
case <-timeout:
panic("QWE")
t.Fatal("expected RepeatTimer to fire")
}
}
@ -43,7 +42,7 @@ func TestRepeat(t *testing.T) {
}
tm := NewLogicalTickerMaker(ch)
dur := time.Duration(0) // dontcare
dur := time.Duration(10 * time.Millisecond) // less than a second
rt := NewRepeatTimerWithTickerMaker("bar", dur, tm)
// Start at 0.


Loading…
Cancel
Save