OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015 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 // Timer is a wrapper around the time.Timer structure. |
| 12 type Timer interface { |
| 13 GetC() <-chan time.Time // Returns the underlying timer's channel, o
r nil if not configured. |
| 14 Reset(d time.Duration) bool // See time.Timer. |
| 15 Stop() bool // See time.Timer. |
| 16 } |
| 17 |
| 18 // |
| 19 // systemTimer |
| 20 // |
| 21 |
| 22 // A Timer implementation that uses time.Timer. |
| 23 type systemTimer struct { |
| 24 T *time.Timer // The underlying timer. Starts as nil, is initialized on
Reset. |
| 25 } |
| 26 |
| 27 // Implements Timer. |
| 28 func (t *systemTimer) GetC() (c <-chan time.Time) { |
| 29 if t.T != nil { |
| 30 c = t.T.C |
| 31 } |
| 32 return |
| 33 } |
| 34 |
| 35 // Implements Timer. |
| 36 func (t *systemTimer) Reset(d time.Duration) bool { |
| 37 if t.T == nil { |
| 38 t.T = time.NewTimer(d) |
| 39 return false |
| 40 } |
| 41 return t.T.Reset(d) |
| 42 } |
| 43 |
| 44 // Implements Timer. |
| 45 func (t *systemTimer) Stop() bool { |
| 46 if t.T == nil { |
| 47 return false |
| 48 } |
| 49 return t.T.Stop() |
| 50 } |
OLD | NEW |