| Index: go/src/infra/libs/clock/timer.go
|
| diff --git a/go/src/infra/libs/clock/timer.go b/go/src/infra/libs/clock/timer.go
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..da8874d0da3fe6c08932f7f1116527b193a2a80d
|
| --- /dev/null
|
| +++ b/go/src/infra/libs/clock/timer.go
|
| @@ -0,0 +1,50 @@
|
| +// 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 clock
|
| +
|
| +import (
|
| + "time"
|
| +)
|
| +
|
| +// Timer is a wrapper around the time.Timer structure.
|
| +type Timer interface {
|
| + GetC() <-chan time.Time // Returns the underlying timer's channel, or nil if not configured.
|
| + Reset(d time.Duration) bool // See time.Timer.
|
| + Stop() bool // See time.Timer.
|
| +}
|
| +
|
| +//
|
| +// systemTimer
|
| +//
|
| +
|
| +// A Timer implementation that uses time.Timer.
|
| +type systemTimer struct {
|
| + T *time.Timer // The underlying timer. Starts as nil, is initialized on Reset.
|
| +}
|
| +
|
| +// 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()
|
| +}
|
|
|