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

Side by Side Diff: common/clock/systemclock.go

Issue 1679023005: Add Context cancellation to clock. (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: Actually upload the patch. Created 4 years, 10 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 | « common/clock/external_test.go ('k') | common/clock/systemclock_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package clock 5 package clock
6 6
7 import ( 7 import (
8 "time" 8 "time"
9
10 "golang.org/x/net/context"
9 ) 11 )
10 12
11 // Implementation of Clock that uses Go's standard library. 13 // Implementation of Clock that uses Go's standard library.
12 type systemClock struct{} 14 type systemClock struct{}
13 15
14 // System clock instance. 16 // System clock instance.
15 var systemClockInstance systemClock 17 var systemClockInstance systemClock
16 18
17 var _ Clock = systemClock{} 19 var _ Clock = systemClock{}
18 20
19 // GetSystemClock returns an instance of a Clock whose method calls directly use 21 // GetSystemClock returns an instance of a Clock whose method calls directly use
20 // Go's "time" library. 22 // Go's "time" library.
21 func GetSystemClock() Clock { 23 func GetSystemClock() Clock {
22 return systemClockInstance 24 return systemClockInstance
23 } 25 }
24 26
25 func (systemClock) Now() time.Time { 27 func (systemClock) Now() time.Time {
26 return time.Now() 28 return time.Now()
27 } 29 }
28 30
29 func (systemClock) Sleep(d time.Duration) { 31 func (sc systemClock) Sleep(c context.Context, d time.Duration) error {
30 » time.Sleep(d) 32 » ar := <-sc.After(c, d)
33 » return ar.Err
31 } 34 }
32 35
33 func (systemClock) NewTimer() Timer { 36 func (systemClock) NewTimer(ctx context.Context) Timer {
34 » return new(systemTimer) 37 » return newSystemTimer(ctx)
35 } 38 }
36 39
37 func (systemClock) After(d time.Duration) <-chan time.Time { 40 func (sc systemClock) After(ctx context.Context, d time.Duration) <-chan TimerRe sult {
38 » return time.After(d) 41 » t := sc.NewTimer(ctx)
42 » t.Reset(d)
43 » return t.GetC()
39 } 44 }
OLDNEW
« no previous file with comments | « common/clock/external_test.go ('k') | common/clock/systemclock_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698