func Once(wait int64, callback func(interface{}), options interface{})
Once executes the given callback function after the given time (in milliseconds) once
func SerializeNumber(num *Number) string
SerializeNumber serializes an instance of timed.Number into a string
func SerializeState(state *State) string
Event represents an event that occurs at certian interval and exeutes pre-registered operations
type Event struct {
// contains filtered or unexported fields
}
func NewEvent(interval int64) (*Event, error)
func (event *Event) OnError(callback func(error))
OnError registers a callback function to be executed if callbacks panics at event tick
func (event *Event) OnTick(callback func())
OnTick registers a callback function to be executed at every event interval (tick)
func (event *Event) Start()
Start starts the timed event
func (event *Event) Stop()
Stop stops the timed event
Number represents a number (int) that changes over time either increment or decrement as time passes
type Number struct {
// contains filtered or unexported fields
}
func DeserializeNumber(str string) (*Number, error)
DeserializeNumber deserializes a serialized string of an instance of timed.Number
func NewNumber(start, min, max, step int, interval int64) (*Number, error)
New creates a new intance of timed.Number
func (num *Number) Decr(val int)
Decr decrements the value by the given value
func (num *Number) Decrementer()
Decrementer instance will decrement by step at each interval
func (num *Number) GetCurrentValue() int
GetCurrentValue returns the current value
func (num *Number) GetProperties() (int, int, int, int, int64)
GetProperties returns all properties: start, min, max, step, interval
func (num *Number) Incr(val int)
Incr increments the value by the given value
func (num *Number) Incrementer()
Incrementer instance will increment by step at each interval
func (num *Number) IsDecrementer() bool
IsDecrementer returns true if the instance is decrementer
func (num *Number) IsIncrementer() bool
IsIncrementer returns true if the instance is incrementer
func (num *Number) Set(val int)
Set sets the current value to be the given value
func (num *Number) Start() bool
Start starts the instance
func (num *Number) ToMax()
ToMax sets the current value to be max
func (num *Number) ToMin()
ToMin sets the current value to be min
type Queue struct { sync.RWMutex // contains filtered or unexported fields }
func NewQueue(interval int64) *Queue
NewQueue creates a new timed queue with interval if interval is 0, queue will not start and Add() will execute operation immediately
func (q *Queue) Add(operation func())
Add adds a new operation into queue
func (q *Queue) Reset()
Reset stops queue and discards all operations in the queue
func (q *Queue) Start()
Start starts the queue
func (q *Queue) Stop()
Stop stops queue, but keeps the items in the queue
State represents a state (int) that changes over time either forward or backward as time passes
type State struct {
// contains filtered or unexported fields
}
func DeserializeState(str string) (*State, error)
func NewState(states []int, start int, interval int64) (*State, error)
func (state *State) Back(step int)
Moves the state backwards by the given value
func (state *State) Backward()
Backward the change direction of the state will be backward
func (state *State) Circular()
Circular defines the state to be a circlar - meaning the change of state does not stop
func (state *State) Forward()
Forward the change direction of the state will be forward
func (state *State) GetCurrentState() int
GetCurrentState returns the current state
func (state *State) GetProperties() ([]int, int64)
GetProperties returns the properties: states, interval
func (state *State) Next(step int)
Next moves the state forward by the given value
func (state *State) NonCircular()
NonCircular defines the state to be a non-circular - meaning the change of state stops at the either begining or the end
func (state *State) Start()
Start starts the state instance
func (state *State) ToEnd()
ToEnd moves the state to the end state of the states array
func (state *State) ToStart()
ToStart moves the state to the first state of the states array