Chromium Code Reviews| Index: go/src/infra/libs/clock/systemclock/timer.go |
| diff --git a/go/src/infra/libs/clock/systemclock/timer.go b/go/src/infra/libs/clock/systemclock/timer.go |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..23eb11ef022656a34134f732514e57a81868a98c |
| --- /dev/null |
| +++ b/go/src/infra/libs/clock/systemclock/timer.go |
| @@ -0,0 +1,39 @@ |
| +// Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package systemclock |
| + |
| +import ( |
| + "time" |
| +) |
| + |
| +// A Timer implementation that uses time.Timer. |
| +type systemTimer struct { |
| + T *time.Timer // The underlying timer. Starts as nil, is initialized on Reset. |
| +} |
|
iannucci
2015/06/02 22:19:03
var _ clock.Timer = (*systemTimer)(nil) // since
dnj
2015/06/03 00:25:28
Done.
|
| + |
| +// Implements Timer. |
| +func (t *systemTimer) GetC() (c <-chan time.Time) { |
| + if t.T != nil { |
| + c = t.T.C |
| + } |
| + return |
| +} |
| + |
| +// Implements Timer. |
| +func (t *systemTimer) Reset(d time.Duration) bool { |
| + if t.T == nil { |
| + t.T = time.NewTimer(d) |
| + return false |
| + } |
| + return t.T.Reset(d) |
| +} |
| + |
| +// Implements Timer. |
| +func (t *systemTimer) Stop() bool { |
| + if t.T == nil { |
| + return false |
| + } |
| + return t.T.Stop() |
| +} |