Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Unified Diff: go/src/infra/libs/clock/systemclock/timer.go

Issue 1154213012: Add context-aware "time" library wrapper. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Refactored into sub-packages. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: go/src/infra/libs/clock/systemclock/timer.go
diff --git a/go/src/infra/libs/clock/systemclock/timer.go b/go/src/infra/libs/clock/systemclock/timer.go
new file mode 100644
index 0000000000000000000000000000000000000000..23eb11ef022656a34134f732514e57a81868a98c
--- /dev/null
+++ b/go/src/infra/libs/clock/systemclock/timer.go
@@ -0,0 +1,39 @@
+// Copyright (c) 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package systemclock
+
+import (
+ "time"
+)
+
+// A Timer implementation that uses time.Timer.
+type systemTimer struct {
+ T *time.Timer // The underlying timer. Starts as nil, is initialized on Reset.
+}
iannucci 2015/06/02 22:19:03 var _ clock.Timer = (*systemTimer)(nil) // since
dnj 2015/06/03 00:25:28 Done.
+
+// Implements Timer.
+func (t *systemTimer) GetC() (c <-chan time.Time) {
+ if t.T != nil {
+ c = t.T.C
+ }
+ return
+}
+
+// Implements Timer.
+func (t *systemTimer) Reset(d time.Duration) bool {
+ if t.T == nil {
+ t.T = time.NewTimer(d)
+ return false
+ }
+ return t.T.Reset(d)
+}
+
+// Implements Timer.
+func (t *systemTimer) Stop() bool {
+ if t.T == nil {
+ return false
+ }
+ return t.T.Stop()
+}

Powered by Google App Engine
This is Rietveld 408576698