-
Notifications
You must be signed in to change notification settings - Fork 0
/
clock.go
53 lines (39 loc) · 1.43 KB
/
clock.go
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
48
49
50
51
52
53
// Package clock provides primitives for mocking time.
package clock
import (
"time"
"google.golang.org/protobuf/types/known/timestamppb"
)
// Clock provides capabilities from the time standard library package.
type Clock interface {
// After waits for the duration to elapse and then sends the current time on the returned channel.
After(duration time.Duration) <-chan time.Time
// AfterFunc waits for the duration to elapse and then calls the function f given to it.
AfterFunc(d time.Duration, f func()) Timer
// NewTicker returns a new Ticker.
NewTicker(d time.Duration) Ticker
// Now returns the current local time.
Now() time.Time
// NowProto returns a new Protobuf timestamp representing the current local time.
NowProto() *timestamppb.Timestamp
// Since returns the time elapsed since t.
Since(t time.Time) time.Duration
// Sleep pauses the current goroutine for at least the duration d.
// A negative or zero duration causes Sleep to return immediately.
Sleep(d time.Duration)
}
// Ticker wraps the time.Ticker class.
type Ticker interface {
// C returns the channel on which the ticks are delivered.
C() <-chan time.Time
// Stop the Ticker.
Stop()
// Reset stops the trigger and next trigger will after the newly given duration has passed.
Reset(duration time.Duration)
}
type Timer interface {
// C returns the channel on which the timer is going to be triggered.
C() <-chan time.Time
// Stop the Timer.
Stop() bool
}