timer

package
Version: v2.1.1+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 22, 2017 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package timer provides various enhanced timer functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RandTicker

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

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

func (tkr *RandTicker) Stop()

Stop stops the ticker and closes the underlying channel.

type Timer

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

func NewTimer(interval time.Duration) *Timer

NewTimer creates a new Timer object

func (*Timer) Interval

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

Interval returns the current interval.

func (*Timer) SetInterval

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

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

func (*Timer) Start

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

Start starts the timer.

func (*Timer) Stop

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

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

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

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL