Documentation ¶
Overview ¶
Package timer provides basic schedule primitives for user defined methods to be engaged after set period.
Index ¶
- Constants
- type Handler
- type HandlerFunc
- type Timer
- func (t *Timer) Cancel(iden int64)
- func (t *Timer) Repeat(d time.Duration, concurr int, handle Handler) (iden int64)
- func (t *Timer) RepeatFunc(d time.Duration, concurr int, handle func(int64)) (iden int64)
- func (t *Timer) Sched(c time.Time, handle Handler) (iden int64)
- func (t *Timer) SchedFunc(c time.Time, handle func(int64)) (iden int64)
- func (t *Timer) Tic()
- func (t *Timer) Toc()
- func (t *Timer) Update(iden int64, c time.Time)
Constants ¶
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 ¶
Cancel takes an identifier by SchedFunc or Sched and disables the handler. Effectively prevents the handler to be invoked.
func (*Timer) Repeat ¶
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 ¶
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 ¶
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 ¶
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.