-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from grafana/chore/remove-time
Remove time package
- Loading branch information
Showing
7 changed files
with
54 additions
and
244 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
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,14 @@ | ||
package ring | ||
|
||
import "time" | ||
|
||
// newDisableableTicker essentially wraps NewTicker but allows the ticker to be disabled by passing | ||
// zero duration as the interval. Returns a function for stopping the ticker, and the ticker channel. | ||
func newDisableableTicker(interval time.Duration) (func(), <-chan time.Time) { | ||
if interval == 0 { | ||
return func() {}, nil | ||
} | ||
|
||
tick := time.NewTicker(interval) | ||
return func() { tick.Stop() }, tick.C | ||
} |
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,34 @@ | ||
package ring | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestNewDisableableTicker_Enabled(t *testing.T) { | ||
stop, ch := newDisableableTicker(10 * time.Millisecond) | ||
defer stop() | ||
|
||
time.Sleep(100 * time.Millisecond) | ||
|
||
select { | ||
case <-ch: | ||
break | ||
default: | ||
t.Error("ticker should have ticked when enabled") | ||
} | ||
} | ||
|
||
func TestNewDisableableTicker_Disabled(t *testing.T) { | ||
stop, ch := newDisableableTicker(0) | ||
defer stop() | ||
|
||
time.Sleep(100 * time.Millisecond) | ||
|
||
select { | ||
case <-ch: | ||
t.Error("ticker should not have ticked when disabled") | ||
default: | ||
break | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.