diff options
Diffstat (limited to 'vendor/github.com/dexon-foundation/dexon-consensus/core/ticker.go')
-rw-r--r-- | vendor/github.com/dexon-foundation/dexon-consensus/core/ticker.go | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/ticker.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/ticker.go index f8d0c67d9..ffd5ab45d 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus/core/ticker.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/ticker.go @@ -36,12 +36,16 @@ const ( // defaultTicker is a wrapper to implement ticker interface based on // time.Ticker. type defaultTicker struct { - ticker *time.Ticker + ticker *time.Ticker + duration time.Duration } // newDefaultTicker constructs an defaultTicker instance by giving an interval. func newDefaultTicker(lambda time.Duration) *defaultTicker { - return &defaultTicker{ticker: time.NewTicker(lambda)} + return &defaultTicker{ + ticker: time.NewTicker(lambda), + duration: lambda, + } } // Tick implements Tick method of ticker interface. @@ -54,6 +58,12 @@ func (t *defaultTicker) Stop() { t.ticker.Stop() } +// Restart implements Stop method of ticker interface. +func (t *defaultTicker) Restart() { + t.ticker.Stop() + t.ticker = time.NewTicker(t.duration) +} + // newTicker is a helper to setup a ticker by giving an Governance. If // the governace object implements a ticker generator, a ticker from that // generator would be returned, else constructs a default one. |