timer

package
v0.0.0-...-5df59a4 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2015 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package timer provides basic schedule primitives for user defined methods to be engaged after set period.

Index

Constants

View Source
const (
	IDLE int = iota
	STARTED
	STOPPED
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler interface {
	Done(jobId int64)
}

Handler is the standard interface for Timer scheduler

type HandlerFunc

type HandlerFunc func(int64)

HandlerFunc is a wrapper type for standard function

func (HandlerFunc) Done

func (e HandlerFunc) Done(jobId int64)

type Timer

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

func NewTimer

func NewTimer() (t *Timer)

NewTimer creates a Timer object. Timer is initialized by not engaged. To enage the Timer, invoke Tic. To stop the Timer, invoke Toc.

func (*Timer) Cancel

func (t *Timer) Cancel(iden int64)

Cancel takes an identifier by SchedFunc or Sched and disables the handler. Effectively prevents the handler to be invoked.

func (*Timer) Repeat

func (t *Timer) Repeat(d time.Duration, concurr int, handle Handler) (iden int64)

Repeat accepts a time.Duration, concurrent limit, and a Handler interface. handler is invoked in its own goroutine at set interval. Only set concurrent limit of task will be spawned at any given moment Returns an identifier for caller to Cancel.

func (*Timer) RepeatFunc

func (t *Timer) RepeatFunc(d time.Duration, concurr int, handle func(int64)) (iden int64)

RepeatFunc accepts a time.Duration, concurrent limit, and a handle function. handle function is invoked in its own goroutine at set interval. Only set concurrent limit of task will be spawned at any given moment Returns an identifier for caller to Cancel.

func (*Timer) Sched

func (t *Timer) Sched(c time.Time, handle Handler) (iden int64)

Sched accepts time.Time object and a Handler interface. handler is invoked in its own goroutine when at designated time. Returns an identifier for caller to Cancel or Update.

func (*Timer) SchedFunc

func (t *Timer) SchedFunc(c time.Time, handle func(int64)) (iden int64)

SchedFunc accepts time.Time object and a handle function. handle function is invoked in its own goroutine at designated time. Returns an identifier for caller to Cancel or Update.

func (*Timer) Tic

func (t *Timer) Tic()

Tic starts the Timer in a goroutine. Accepts incoming schedudle request via SchedFunc and Sched.

func (*Timer) Toc

func (t *Timer) Toc()

Toc stops the Timer and all schedudled handler are dropped. Stopped timer cannot be restarted.

func (*Timer) Update

func (t *Timer) Update(iden int64, c time.Time)

Update takes an identifier by SchedFunc or Sched and reschedules its TTL.

Jump to

Keyboard shortcuts

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