File: wall.go

package info (click to toggle)
golang-github-juju-clock 1.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 176 kB
  • sloc: makefile: 18
file content (47 lines) | stat: -rw-r--r-- 1,061 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright 2015 Canonical Ltd.
// Licensed under the LGPLv3, see LICENCE file for details.

package clock

import (
	"time"
)

// WallClock exposes wall-clock time via the Clock interface.
var WallClock wallClock

// ensure that WallClock does actually implement the Clock interface.
var _ Clock = WallClock

// WallClock exposes wall-clock time as returned by time.Now.
type wallClock struct{}

// Now is part of the Clock interface.
func (wallClock) Now() time.Time {
	return time.Now()
}

// After implements Clock.After.
func (wallClock) After(d time.Duration) <-chan time.Time {
	return time.After(d)
}

// AfterFunc implements Clock.AfterFunc.
func (wallClock) AfterFunc(d time.Duration, f func()) Timer {
	return wallTimer{time.AfterFunc(d, f)}
}

// NewTimer implements Clock.NewTimer.
func (wallClock) NewTimer(d time.Duration) Timer {
	return wallTimer{time.NewTimer(d)}
}

// wallTimer implements the Timer interface.
type wallTimer struct {
	*time.Timer
}

// Chan implements Timer.Chan.
func (t wallTimer) Chan() <-chan time.Time {
	return t.C
}