blob: 9bfc351855626a6ff047e2ab2d606f5518755068 [file] [log] [blame]
David K. Bainbridge528b3182017-01-23 08:51:59 -08001// Copyright 2015 Canonical Ltd.
2// Licensed under the LGPLv3, see LICENCE file for details.
3
4package clock
5
6import (
7 "time"
8)
9
10// WallClock exposes wall-clock time via the Clock interface.
11var WallClock wallClock
12
13// ensure that WallClock does actually implement the Clock interface.
14var _ Clock = WallClock
15
16// WallClock exposes wall-clock time as returned by time.Now.
17type wallClock struct{}
18
19// Now is part of the Clock interface.
20func (wallClock) Now() time.Time {
21 return time.Now()
22}
23
24// After implements Clock.After.
25func (wallClock) After(d time.Duration) <-chan time.Time {
26 return time.After(d)
27}
28
29// AfterFunc implements Clock.AfterFunc.
30func (wallClock) AfterFunc(d time.Duration, f func()) Timer {
31 return wallTimer{time.AfterFunc(d, f)}
32}
33
34// NewTimer implements Clock.NewTimer.
35func (wallClock) NewTimer(d time.Duration) Timer {
36 return wallTimer{time.NewTimer(d)}
37}
38
39// wallTimer implements the Timer interface.
40type wallTimer struct {
41 *time.Timer
42}
43
44// Chan implements Timer.Chan.
45func (t wallTimer) Chan() <-chan time.Time {
46 return t.C
47}