1// Copyright The OpenTelemetry Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package time // import "go.opentelemetry.io/otel/sdk/metric/controller/time"
16
17import (
18	"time"
19	lib "time"
20)
21
22// Several types below are created to match "github.com/benbjohnson/clock"
23// so that it remains a test-only dependency.
24
25type Clock interface {
26	Now() lib.Time
27	Ticker(duration lib.Duration) Ticker
28}
29
30type Ticker interface {
31	Stop()
32	C() <-chan lib.Time
33}
34
35type RealClock struct {
36}
37
38type RealTicker struct {
39	ticker *lib.Ticker
40}
41
42var _ Clock = RealClock{}
43var _ Ticker = RealTicker{}
44
45func (RealClock) Now() time.Time {
46	return time.Now()
47}
48
49func (RealClock) Ticker(period time.Duration) Ticker {
50	return RealTicker{time.NewTicker(period)}
51}
52
53func (t RealTicker) Stop() {
54	t.ticker.Stop()
55}
56
57func (t RealTicker) C() <-chan time.Time {
58	return t.ticker.C
59}
60