diff --git a/README.md b/README.md index a3f2580..012ed44 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ can use the realtime clock while tests can use the mock clock. ### Realtime Clock Your application can maintain a `Clock` variable that will allow realtime and -mock clocks to be interchangable. For example, if you had an `Application` type: +mock clocks to be interchangeable. For example, if you had an `Application` type: ```go import "github.com/benbjohnson/clock" @@ -55,7 +55,7 @@ func TestApplication_DoSomething(t *testing.T) { Now that you've initialized your application to use the mock clock, you can adjust the time programmatically. The mock clock always starts from the Unix -epoch (midnight, Jan 1, 1970 UTC). +epoch (midnight UTC on Jan 1, 1970). ### Controlling time @@ -94,7 +94,7 @@ go func() { }() runtime.Gosched() -// Move the clock forward 10 second. +// Move the clock forward 10 seconds. mock.Add(10 * time.Second) // This prints 10. diff --git a/clock.go b/clock.go index a48e6ac..ab7ebc5 100644 --- a/clock.go +++ b/clock.go @@ -9,7 +9,7 @@ import ( // Clock represents an interface to the functions in the standard library time // package. Two implementations are available in the clock package. The first // is a real-time clock which simply wraps the time package's functions. The -// second is a mock clock which will only make forward progress when +// second is a mock clock which will only change when // programmatically adjusted. type Clock interface { After(d time.Duration) <-chan time.Time @@ -54,7 +54,7 @@ func (c *clock) Timer(d time.Duration) *Timer { return &Timer{C: t.C, timer: t} } -// Mock represents a mock clock that only moves forward programmically. +// Mock represents a mock clock that only moves forward programmatically. // It can be preferable to a real-time clock when testing time-based functionality. type Mock struct { mu sync.Mutex @@ -68,7 +68,7 @@ func NewMock() *Mock { return &Mock{now: time.Unix(0, 0)} } -// Add moves the current time of the mock clock forward by the duration. +// Add moves the current time of the mock clock forward by the specified duration. // This should only be called from a single goroutine at a time. func (m *Mock) Add(d time.Duration) { // Calculate the final current time. @@ -86,7 +86,7 @@ func (m *Mock) Add(d time.Duration) { m.now = t m.mu.Unlock() - // Give a small buffer to make sure the other goroutines get handled. + // Give a small buffer to make sure that other goroutines get handled. gosched() } @@ -105,13 +105,13 @@ func (m *Mock) Set(t time.Time) { m.now = t m.mu.Unlock() - // Give a small buffer to make sure the other goroutines get handled. + // Give a small buffer to make sure that other goroutines get handled. gosched() } // runNextTimer executes the next timer in chronological order and moves the // current time to the timer's next tick time. The next time is not executed if -// it's next time if after the max time. Returns true if a timer is executed. +// its next time is after the max time. Returns true if a timer was executed. func (m *Mock) runNextTimer(max time.Time) bool { m.mu.Lock() @@ -161,7 +161,7 @@ func (m *Mock) Now() time.Time { return m.now } -// Since returns time since the mock clocks wall time. +// Since returns time since the mock clock's wall time. func (m *Mock) Since(t time.Time) time.Duration { return m.Now().Sub(t) } diff --git a/clock_test.go b/clock_test.go index 322b742..70cc7c7 100644 --- a/clock_test.go +++ b/clock_test.go @@ -334,7 +334,7 @@ func TestMock_Sleep(t *testing.T) { t.Fatal("too early") } - // Move clock forward to the after the sleep duration. + // Move clock forward to after the sleep duration. clock.Add(1 * time.Second) if atomic.LoadInt32(&ok) == 0 { t.Fatal("too late")