Skip to content

Commit 3ff779b

Browse files
Added a timer interface (#387)
Signed-off-by: Yash Sharma <[email protected]>
1 parent 468f615 commit 3ff779b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

interceptors/reporter.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,23 @@ import (
1414

1515
type GRPCType string
1616

17+
// Timer is a helper interface to time functions.
18+
// Useful for interceptors to record the total
19+
// time elapsed since completion of a call.
20+
type Timer interface {
21+
ObserveDuration() time.Duration
22+
}
23+
24+
// zeroTimer.
25+
type zeroTimer struct {
26+
}
27+
28+
func (zeroTimer) ObserveDuration() time.Duration {
29+
return 0
30+
}
31+
32+
var EmptyTimer = &zeroTimer{}
33+
1734
const (
1835
Unary GRPCType = "unary"
1936
ClientStream GRPCType = "client_stream"

0 commit comments

Comments
 (0)