go-vitess.v1: gopkg.in/src-d/go-vitess.v1/timer Index | Files

package timer

import "gopkg.in/src-d/go-vitess.v1/timer"

Package timer provides various enhanced timer functions.

Index

Package Files

randticker.go timer.go

type RandTicker Uses

type RandTicker struct {
    C <-chan time.Time
    // contains filtered or unexported fields
}

RandTicker is just like time.Ticker, except that it adds randomness to the events.

func NewRandTicker Uses

func NewRandTicker(d, variance time.Duration) *RandTicker

NewRandTicker creates a new RandTicker. d is the duration, and variance specifies the variance. The ticker will tick every d +/- variance.

func (*RandTicker) Stop Uses

func (tkr *RandTicker) Stop()

Stop stops the ticker and closes the underlying channel.

type Timer Uses

type Timer struct {
    // contains filtered or unexported fields
}

Timer provides timer functionality that can be controlled by the user. You start the timer by providing it a callback function, which it will call at the specified interval.

var t = timer.NewTimer(1e9)
t.Start(KeepHouse)

func KeepHouse() {
	// do house keeping work
}

You can stop the timer by calling t.Stop, which is guaranteed to wait if KeepHouse is being executed.

You can create an untimely trigger by calling t.Trigger. You can also schedule an untimely trigger by calling t.TriggerAfter.

The timer interval can be changed on the fly by calling t.SetInterval. A zero value interval will cause the timer to wait indefinitely, and it will react only to an explicit Trigger or Stop.

func NewTimer Uses

func NewTimer(interval time.Duration) *Timer

NewTimer creates a new Timer object

func (*Timer) Interval Uses

func (tm *Timer) Interval() time.Duration

Interval returns the current interval.

func (*Timer) SetInterval Uses

func (tm *Timer) SetInterval(ns time.Duration)

SetInterval changes the wait interval. It will cause the timer to restart the wait.

func (*Timer) Start Uses

func (tm *Timer) Start(keephouse func())

Start starts the timer.

func (*Timer) Stop Uses

func (tm *Timer) Stop()

Stop will stop the timer. It guarantees that the timer will not execute any more calls to keephouse once it has returned.

func (*Timer) Trigger Uses

func (tm *Timer) Trigger()

Trigger will cause the timer to immediately execute the keephouse function. It will then cause the timer to restart the wait.

func (*Timer) TriggerAfter Uses

func (tm *Timer) TriggerAfter(duration time.Duration)

TriggerAfter waits for the specified duration and triggers the next event.

Package timer imports 4 packages (graph) and is imported by 10 packages. Updated 2019-06-13. Refresh now. Tools for package owners.