OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | |
iannucci
2015/06/02 22:19:02
(copyrights)
Also, as discussed, I think it makes
dnj
2015/06/03 00:25:28
Done.
| |
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 systemclock | |
6 | |
7 import ( | |
8 "time" | |
9 | |
10 "golang.org/x/net/context" | |
11 "infra/libs/clock" | |
12 ) | |
13 | |
14 // Implementation of Clock that uses Go's standard library. | |
15 type systemClock struct{} | |
16 | |
17 // System clock instance. | |
18 var systemClockInstance systemClock | |
19 | |
20 // systemClock implements clock.Clock. | |
21 var _ clock.Clock = (*systemClock)(nil) | |
iannucci
2015/06/02 22:19:03
I think this would be even better as
var _ cloc
dnj
2015/06/03 00:25:28
Done.
| |
22 | |
23 // Get returns an instance of a Clock whose method calls directly use Go's "time " | |
24 // library. | |
25 func Get() clock.Clock { | |
26 return systemClockInstance | |
27 } | |
28 | |
29 func (systemClock) Now() time.Time { | |
30 return time.Now() | |
31 } | |
32 | |
33 func (systemClock) Sleep(d time.Duration) { | |
34 time.Sleep(d) | |
35 } | |
36 | |
37 func (systemClock) NewTimer() clock.Timer { | |
38 return new(systemTimer) | |
39 } | |
40 | |
41 func (systemClock) After(d time.Duration) <-chan time.Time { | |
42 return time.After(d) | |
43 } | |
44 | |
45 // Set creates a new Context using the supplied TestClock instance. | |
46 func Set(ctx context.Context) context.Context { | |
47 return clock.SetClock(ctx, Get()) | |
48 } | |
OLD | NEW |