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

Side by Side Diff: common/clock/timer.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/testclock/testtimer_test.go ('k') | common/gcloud/pubsub/ackbuffer/ackbuffer.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 ) 9 )
10 10
11 // Timer is a wrapper around the time.Timer structure. 11 // Timer is a wrapper around the time.Timer structure.
12 // 12 //
13 // A Timer is instantiated from a Clock instance and started via its Reset() 13 // A Timer is instantiated from a Clock instance and started via its Reset()
14 // method. 14 // method.
15 type Timer interface { 15 type Timer interface {
16 » // GetC returns the underlying timer's channel, or nil if the timer is n o 16 » // GetC returns the underlying timer's channel.
17 » // running. 17 » //
18 » GetC() <-chan time.Time 18 » // If the Timer is interrupted via Stop, its channel will block indefini tely.
19 » GetC() <-chan TimerResult
19 20
20 // Reset configures the timer to expire after a specified duration. 21 // Reset configures the timer to expire after a specified duration.
21 // 22 //
22 // If the timer is already running, its previous state will be cleared a nd 23 // If the timer is already running, its previous state will be cleared a nd
23 » // this method will return true. 24 » // this method will return true. The channel returned by GetC() will not
25 » // change due to Reset.
24 Reset(d time.Duration) bool 26 Reset(d time.Duration) bool
25 27
26 // Stop clears any timer tasking, rendering it inactive. 28 // Stop clears any timer tasking, rendering it inactive.
27 // 29 //
28 // Stop may be called on an inactive timer, in which case nothing will h appen 30 // Stop may be called on an inactive timer, in which case nothing will h appen
29 » // If the timer is active, it will be stopped and this method will retur n true. 31 » // If the timer is active, it will be stopped and this method will retur n
32 » // true.
33 » //
34 » // If a timer is stopped, its GetC channel will block indefinitely to av oid
35 » // erroneously unblocking goroutines that are waiting on it. This is
36 » // consistent with time.Timer.
30 Stop() bool 37 Stop() bool
31 } 38 }
39
40 // TimerResult is the result for a timer operation.
41 //
42 // Time will be set to the time when the result was generated. If the source of
43 // the result was prematurely terminated (e.g., due to Context cancellation)
44 // Err will be non-nil.
45 type TimerResult struct {
46 time.Time
47
48 // Err, if not nil, indicates that After did not finish naturally and co ntains
49 // the reason why.
50 Err error
51 }
OLDNEW
« no previous file with comments | « common/clock/testclock/testtimer_test.go ('k') | common/gcloud/pubsub/ackbuffer/ackbuffer.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698