summaryrefslogtreecommitdiff
path: root/vendor/k8s.io/apimachinery/pkg/util/clock/clock.go
diff options
context:
space:
mode:
authorValentin Rothberg <rothberg@redhat.com>2019-06-24 21:29:31 +0200
committerValentin Rothberg <rothberg@redhat.com>2019-06-24 21:29:31 +0200
commit2388222e98462fdbbe44f3e091b2b79d80956a9a (patch)
tree17078d861c20a3e48b19c750c6864c5f59248386 /vendor/k8s.io/apimachinery/pkg/util/clock/clock.go
parenta1a4a75abee2c381483a218e1660621ee416ef7c (diff)
downloadpodman-2388222e98462fdbbe44f3e091b2b79d80956a9a.tar.gz
podman-2388222e98462fdbbe44f3e091b2b79d80956a9a.tar.bz2
podman-2388222e98462fdbbe44f3e091b2b79d80956a9a.zip
update dependencies
Ran a `go get -u` and bumped K8s deps to 1.15.0. Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'vendor/k8s.io/apimachinery/pkg/util/clock/clock.go')
-rw-r--r--vendor/k8s.io/apimachinery/pkg/util/clock/clock.go63
1 files changed, 42 insertions, 21 deletions
diff --git a/vendor/k8s.io/apimachinery/pkg/util/clock/clock.go b/vendor/k8s.io/apimachinery/pkg/util/clock/clock.go
index c303a212a..9567f9006 100644
--- a/vendor/k8s.io/apimachinery/pkg/util/clock/clock.go
+++ b/vendor/k8s.io/apimachinery/pkg/util/clock/clock.go
@@ -26,18 +26,12 @@ import (
type Clock interface {
Now() time.Time
Since(time.Time) time.Duration
- After(d time.Duration) <-chan time.Time
- NewTimer(d time.Duration) Timer
- Sleep(d time.Duration)
- Tick(d time.Duration) <-chan time.Time
+ After(time.Duration) <-chan time.Time
+ NewTimer(time.Duration) Timer
+ Sleep(time.Duration)
+ NewTicker(time.Duration) Ticker
}
-var (
- _ = Clock(RealClock{})
- _ = Clock(&FakeClock{})
- _ = Clock(&IntervalClock{})
-)
-
// RealClock really calls time.Now()
type RealClock struct{}
@@ -62,8 +56,10 @@ func (RealClock) NewTimer(d time.Duration) Timer {
}
}
-func (RealClock) Tick(d time.Duration) <-chan time.Time {
- return time.Tick(d)
+func (RealClock) NewTicker(d time.Duration) Ticker {
+ return &realTicker{
+ ticker: time.NewTicker(d),
+ }
}
func (RealClock) Sleep(d time.Duration) {
@@ -137,7 +133,7 @@ func (f *FakeClock) NewTimer(d time.Duration) Timer {
return timer
}
-func (f *FakeClock) Tick(d time.Duration) <-chan time.Time {
+func (f *FakeClock) NewTicker(d time.Duration) Ticker {
f.lock.Lock()
defer f.lock.Unlock()
tickTime := f.time.Add(d)
@@ -149,7 +145,9 @@ func (f *FakeClock) Tick(d time.Duration) <-chan time.Time {
destChan: ch,
})
- return ch
+ return &fakeTicker{
+ c: ch,
+ }
}
// Move clock by Duration, notify anyone that's called After, Tick, or NewTimer
@@ -242,8 +240,8 @@ func (*IntervalClock) NewTimer(d time.Duration) Timer {
// Unimplemented, will panic.
// TODO: make interval clock use FakeClock so this can be implemented.
-func (*IntervalClock) Tick(d time.Duration) <-chan time.Time {
- panic("IntervalClock doesn't implement Tick")
+func (*IntervalClock) NewTicker(d time.Duration) Ticker {
+ panic("IntervalClock doesn't implement NewTicker")
}
func (*IntervalClock) Sleep(d time.Duration) {
@@ -258,11 +256,6 @@ type Timer interface {
Reset(d time.Duration) bool
}
-var (
- _ = Timer(&realTimer{})
- _ = Timer(&fakeTimer{})
-)
-
// realTimer is backed by an actual time.Timer.
type realTimer struct {
timer *time.Timer
@@ -325,3 +318,31 @@ func (f *fakeTimer) Reset(d time.Duration) bool {
return active
}
+
+type Ticker interface {
+ C() <-chan time.Time
+ Stop()
+}
+
+type realTicker struct {
+ ticker *time.Ticker
+}
+
+func (t *realTicker) C() <-chan time.Time {
+ return t.ticker.C
+}
+
+func (t *realTicker) Stop() {
+ t.ticker.Stop()
+}
+
+type fakeTicker struct {
+ c <-chan time.Time
+}
+
+func (t *fakeTicker) C() <-chan time.Time {
+ return t.c
+}
+
+func (t *fakeTicker) Stop() {
+}