1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/vendor/code.cloudfoundry.org/clock/clock.go
Sebastiaan van Stijn b000d5321a
bump docker/swarmkit 59163bf75df38489d4a10392265d27156dc473c5
full diff: 18e7e58ea1...59163bf75d

- Add missing return when configuring VXLAN port
- Prevent possible panic in cnmallocator.IsAttachmentAllocated()
- update github.com/pivotal-golang/clock
  - new name for package: code.cloudfoundry.org/clock

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-04-15 18:04:36 +02:00

53 lines
1.2 KiB
Go

package clock
import "time"
type Clock interface {
Now() time.Time
Sleep(d time.Duration)
Since(t time.Time) time.Duration
// After waits for the duration to elapse and then sends the current time
// on the returned channel.
// It is equivalent to clock.NewTimer(d).C.
// The underlying Timer is not recovered by the garbage collector
// until the timer fires. If efficiency is a concern, use clock.NewTimer
// instead and call Timer.Stop if the timer is no longer needed.
After(d time.Duration) <-chan time.Time
NewTimer(d time.Duration) Timer
NewTicker(d time.Duration) Ticker
}
type realClock struct{}
func NewClock() Clock {
return &realClock{}
}
func (clock *realClock) Now() time.Time {
return time.Now()
}
func (clock *realClock) Since(t time.Time) time.Duration {
return time.Now().Sub(t)
}
func (clock *realClock) Sleep(d time.Duration) {
<-clock.NewTimer(d).C()
}
func (clock *realClock) After(d time.Duration) <-chan time.Time {
return clock.NewTimer(d).C()
}
func (clock *realClock) NewTimer(d time.Duration) Timer {
return &realTimer{
t: time.NewTimer(d),
}
}
func (clock *realClock) NewTicker(d time.Duration) Ticker {
return &realTicker{
t: time.NewTicker(d),
}
}