-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Logdb refactoring and some more tests (#5)
- Loading branch information
Showing
21 changed files
with
669 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package clock | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
// Clock is a time abstraction which can be used to if you need to mock time in tests. | ||
type Clock interface { | ||
Now() time.Time | ||
NewTicker(d time.Duration) (<-chan time.Time, func()) | ||
NewTimer(d time.Duration) (<-chan time.Time, func() bool) | ||
Since(t time.Time) time.Duration | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package clock | ||
|
||
import "time" | ||
|
||
// RealClock imlements the Clock interface using the standard libraries time package. | ||
type RealClock struct{} | ||
|
||
func New() *RealClock { | ||
return &RealClock{} | ||
} | ||
|
||
// Now is a wrapper around time.Now(). | ||
func (c *RealClock) Now() time.Time { | ||
return time.Now() | ||
} | ||
|
||
// NewTicker is a wrapper around time.NewTicker(). | ||
func (c *RealClock) NewTicker(d time.Duration) (<-chan time.Time, func()) { | ||
t := time.NewTicker(d) | ||
return t.C, t.Stop | ||
} | ||
|
||
// NewTimer is a wrapper around time.NewTimer(). | ||
func (c *RealClock) NewTimer(d time.Duration) (<-chan time.Time, func() bool) { | ||
t := time.NewTimer(d) | ||
return t.C, t.Stop | ||
} | ||
|
||
// Since is a wrapper around time.Since(). | ||
func (c *RealClock) Since(t time.Time) time.Duration { | ||
return time.Since(t) | ||
} |
Oops, something went wrong.