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

Side by Side Diff: go/src/infra/libs/clock/clock.go

Issue 1154213012: Add context-aware "time" library wrapper. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 5 years, 6 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 unified diff | Download patch
« no previous file with comments | « no previous file | go/src/infra/libs/clock/context.go » ('j') | go/src/infra/libs/clock/context.go » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package clock
6
7 import (
8 "time"
9 )
10
11 // A Clock is an interface to system time.
12 //
13 // The standard clock is SystemClock, which falls through to the system time lib rary.
14 // Another clock, FakeClock, is available to simulate time facilities for testin g.
15 type Clock interface {
16 Now() time.Time // Returns the current time (see t ime.Now).
17 Sleep(time.Duration) // Sleeps the current goroutine (s ee time.Sleep)
18 NewTimer() Timer // Creates a new Timer instance.
19 After(time.Duration) <-chan time.Time // Waits a duration, then sends th e current time.
20 }
21
22 // Implementation of Clock that uses Go's standard library.
iannucci 2015/06/02 06:15:33 implementations should go in subpackages I think.
23 type systemClock struct{}
24
25 // System clock instance.
26 var systemClockInstance systemClock
27
28 // SystemClock returns an instance of a Clock whose method calls directly use Go 's "time"
29 // library.
30 func SystemClock() Clock {
31 return systemClockInstance
32 }
33
34 // Implements Clock.
35 func (systemClock) Now() time.Time {
36 return time.Now()
37 }
38
39 // Implements Clock.
40 func (systemClock) Sleep(d time.Duration) {
41 time.Sleep(d)
42 }
43
44 // Implements Clock.
45 func (systemClock) NewTimer() Timer {
46 return new(systemTimer)
47 }
48
49 // Implements Clock.
50 func (systemClock) After(d time.Duration) <-chan time.Time {
51 return time.After(d)
52 }
OLDNEW
« no previous file with comments | « no previous file | go/src/infra/libs/clock/context.go » ('j') | go/src/infra/libs/clock/context.go » ('J')

Powered by Google App Engine
This is Rietveld 408576698