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

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

Issue 1154213012: Add context-aware "time" library wrapper. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Removed goroutine safety from testtimer. 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.go
diff --git a/go/src/infra/libs/clock/systemclock.go b/go/src/infra/libs/clock/systemclock.go
new file mode 100644
index 0000000000000000000000000000000000000000..276430efe1d8c36e83e29a919d5dd48c941987d8
--- /dev/null
+++ b/go/src/infra/libs/clock/systemclock.go
@@ -0,0 +1,39 @@
+// Copyright 2014 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 clock
iannucci 2015/06/03 17:37:20 package systemclock
dnj 2015/06/03 18:21:26 Not anymore, is in main "clock" package.
+
+import (
+ "time"
+)
+
+// Implementation of Clock that uses Go's standard library.
+type systemClock struct{}
+
+// System clock instance.
+var systemClockInstance systemClock
+
+var _ Clock = systemClock{}
+
+// GetSystemClock returns an instance of a Clock whose method calls directly use Go's
+// "time" library.
+func GetSystemClock() Clock {
iannucci 2015/06/03 17:37:20 Get
dnj 2015/06/03 18:21:26 (In "clock" package now).
+ return systemClockInstance
+}
+
+func (systemClock) Now() time.Time {
+ return time.Now()
+}
+
+func (systemClock) Sleep(d time.Duration) {
+ time.Sleep(d)
+}
+
+func (systemClock) NewTimer() Timer {
+ return new(systemTimer)
+}
+
+func (systemClock) After(d time.Duration) <-chan time.Time {
+ return time.After(d)
+}

Powered by Google App Engine
This is Rietveld 408576698