зеркало из https://github.com/microsoft/clock.git
docs: fix typos and style to match godoc conventions
This commit is contained in:
Родитель
447faa045c
Коммит
384652fcb1
2
clock.go
2
clock.go
|
@ -27,7 +27,7 @@ type Timer interface {
|
|||
Stop() bool
|
||||
}
|
||||
|
||||
// The Timer is an interface for time.Ticket, and can also be swapped in mocks.
|
||||
// The Ticker is an interface for time.Ticker, and can also be swapped in mocks.
|
||||
// This *does* change its API so that it can fit into an interface -- rather
|
||||
// than using the channel at .C, you should call Chan() and use the
|
||||
// returned channel just as you would .C.
|
||||
|
|
|
@ -54,6 +54,6 @@ func (d *defaultTicker) Chan() <-chan time.Time {
|
|||
return d.C
|
||||
}
|
||||
|
||||
// Default clock that uses time.Now as its time source. This is what you should
|
||||
// C holds a default clock that uses time.Now as its time source. This is what you should
|
||||
// normally use in your code.
|
||||
var C = DefaultClock{}
|
||||
|
|
10
mock.go
10
mock.go
|
@ -70,14 +70,14 @@ func (m *MockClock) AfterFunc(d time.Duration, f func()) Timer {
|
|||
return t
|
||||
}
|
||||
|
||||
// NewTimer creates a new Timer that will send the current time on its channel after at least duration d.
|
||||
// NewTimer creates a new mock Timer that will send the current time on its channel after at least duration d.
|
||||
func (m *MockClock) NewTimer(d time.Duration) Timer {
|
||||
t := NewMockTimer(m)
|
||||
t.Reset(d)
|
||||
return t
|
||||
}
|
||||
|
||||
// NewTimer creates a new Timer that will send the current time on its channel after at least duration d.
|
||||
// NewTicker returns a new mock Ticker containing a channel that will send the time with a period specified by the duration argument.
|
||||
// Note: unlike the default ticker included in Go, the mock ticker will *never* skip ticks as time advances.
|
||||
func (m *MockClock) NewTicker(d time.Duration) Ticker {
|
||||
return NewMockTicker(m, d)
|
||||
|
@ -88,7 +88,7 @@ func (m *MockClock) Since(t time.Time) time.Duration {
|
|||
return m.Now().Sub(t)
|
||||
}
|
||||
|
||||
// Sets the mock clock's time to the given absolute time.
|
||||
// SetTime sets the mock clock's time to the given absolute time.
|
||||
func (m *MockClock) SetTime(t time.Time) {
|
||||
m.cond.L.Lock()
|
||||
defer m.cond.L.Unlock()
|
||||
|
@ -98,7 +98,7 @@ func (m *MockClock) SetTime(t time.Time) {
|
|||
m.cond.Broadcast()
|
||||
}
|
||||
|
||||
// Adds the given time duration to the clock.
|
||||
// AddTime adds the given time duration to the clock.
|
||||
func (m *MockClock) AddTime(d time.Duration) {
|
||||
m.cond.L.Lock()
|
||||
defer m.cond.L.Unlock()
|
||||
|
@ -114,7 +114,7 @@ func assertFuture(a, b time.Time) {
|
|||
}
|
||||
}
|
||||
|
||||
// Creates a new mock clock, with its current time set to the provided
|
||||
// NewMockClock creates a new mock clock, with its current time set to the provided
|
||||
// optional start time.
|
||||
func NewMockClock(start ...time.Time) *MockClock {
|
||||
m := &MockClock{cond: sync.NewCond(new(sync.Mutex))}
|
||||
|
|
|
@ -49,7 +49,7 @@ func (m *mockTicker) Stop() {
|
|||
m.stop <- true
|
||||
}
|
||||
|
||||
// Creates a new Ticker using the provided Clock. You should not use this
|
||||
// NewMockTicker creates a new Ticker using the provided Clock. You should not use this
|
||||
// directly outside of unit tests; use Clock.NewTicker().
|
||||
func NewMockTicker(c Clock, interval time.Duration) Ticker {
|
||||
t := &mockTicker{
|
||||
|
@ -65,4 +65,3 @@ func NewMockTicker(c Clock, interval time.Duration) Ticker {
|
|||
<-ready
|
||||
return t
|
||||
}
|
||||
|
||||
|
|
2
timer.go
2
timer.go
|
@ -70,7 +70,7 @@ func (m *mockTimer) Stop() bool {
|
|||
return wasActive
|
||||
}
|
||||
|
||||
// Creates a new Timer using the provided Clock. You should not use this
|
||||
// NewMockTimer creates a new Timer using the provided Clock. You should not use this
|
||||
// directly outside of unit tests; use Clock.NewTimer().
|
||||
func NewMockTimer(c Clock) Timer {
|
||||
return &mockTimer{
|
||||
|
|
Загрузка…
Ссылка в новой задаче