Skip to content
This repository has been archived by the owner on May 18, 2023. It is now read-only.

Commit

Permalink
Merge pull request #21 from jsoref/grammar
Browse files Browse the repository at this point in the history
Grammar
  • Loading branch information
benbjohnson authored May 11, 2020
2 parents 1c0be5e + cf870e3 commit dcb3cf9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
14 changes: 7 additions & 7 deletions clock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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()
}

Expand All @@ -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()

Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion clock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit dcb3cf9

Please sign in to comment.