Documentation ¶
Index ¶
- Constants
- func GetMD5Hash(text string) string
- func RandTimer(m map[TimerID]*Timer) (TimerID, *Timer)
- type Anagent
- func (a *Anagent) AddRecurringTimerSeconds(seconds int64, handler Handler) TimerID
- func (a *Anagent) AddTimerSeconds(seconds int64, handler Handler) TimerID
- func (a *Anagent) Emit(event interface{}) *Anagent
- func (a *Anagent) EmitSync(event interface{}) *Anagent
- func (a *Anagent) Emitter() *emission.Emitter
- func (a *Anagent) GetTimer(id TimerID) *Timer
- func (a *Anagent) Handlers(handlers ...Handler)
- func (a *Anagent) IsStarted() bool
- func (a *Anagent) Next(handler Handler)
- func (a *Anagent) On(event, listener interface{}) *Anagent
- func (a *Anagent) Once(event, listener interface{}) *Anagent
- func (a *Anagent) RemoveTimer(id TimerID)
- func (a *Anagent) RunLoop()
- func (a *Anagent) SetDuration(id TimerID, after time.Duration) TimerID
- func (a *Anagent) Start()
- func (a *Anagent) Step()
- func (a *Anagent) Stop()
- func (a *Anagent) Timer(tid TimerID, ti time.Time, after time.Duration, recurring bool, ...) TimerID
- func (a *Anagent) TimerSeconds(seconds int64, recurring bool, handler Handler) TimerID
- func (a *Anagent) Use(handler Handler)
- type Handler
- type Timer
- type TimerID
Constants ¶
const VERSION = "0.1"
VERSION contains the Anagent version number
Variables ¶
This section is empty.
Functions ¶
func GetMD5Hash ¶
GetMD5Hash is a utility function to get MD5 digest of the supplied string.
Types ¶
type Anagent ¶
type Anagent struct { inject.Injector sync.Mutex // Fatal bool Started bool BusyLoop bool StartedAccess *sync.Mutex // contains filtered or unexported fields }
Anagent represents the top level application. inject.Injector methods can be invoked to map services on a global level.
func New ¶
func New() *Anagent
New creates a bare bones Anagent instance. Use this method if you want to have full control over the middleware that is used.
func (*Anagent) AddRecurringTimerSeconds ¶
AddRecurringTimerSeconds is used to set a recurring timer, that will fire after the seconds supplied. It requires seconds supplied as int64 and at the end the callback to be fired at the desired time.
func (*Anagent) AddTimerSeconds ¶
AddTimerSeconds is used to set a non recurring timer, that will fire after the seconds supplied. It requires seconds supplied as int64 and at the end the callback to be fired at the desired time.
func (*Anagent) Emit ¶
Emit Emits an event, it does accept only the event as argument, since the callback will have access to the service mapped by the injector
func (*Anagent) EmitSync ¶
EmitSync Emits an event in a syncronized manner, it does accept only the event as argument, since the callback will have access to the service mapped by the injector
func (*Anagent) Emitter ¶
Emitter returns the internal *emission.Emitter used structure use this to access directly to the Emitter, and override the dependency-injection features
func (*Anagent) GetTimer ¶
GetTimer is used to set a get a timer from the loop. It requires a TimerID
func (*Anagent) Handlers ¶
Handlers sets the entire middleware stack with the given Handlers. This will clear any current middleware handlers, and panics if any of the handlers is not a callable function
func (*Anagent) IsStarted ¶
IsStarted returns a boolean indicating if we started the loop with Start()
func (*Anagent) Next ¶
Next adds a middleware Handler to the next tick, and removes it once executed.
func (*Anagent) Once ¶
Once Binds a callback to an event, mapping the arguments on a global level It is fired only once.
func (*Anagent) RemoveTimer ¶
RemoveTimer is used to set a remove a timer from the loop. It requires a TimerID
func (*Anagent) SetDuration ¶
SetDuration is used to change the duration of a timer. It requires a TimerID and a time.Duration
func (*Anagent) Start ¶
func (a *Anagent) Start()
Start starts the agent loop and never returns. ( unless you call Stop() )
func (*Anagent) Step ¶
func (a *Anagent) Step()
Step executes an agent step. It is idempotent, and even if there are delays in timings events gets executed in order as a best-effort in respecting setted timers.
func (*Anagent) Stop ¶
func (a *Anagent) Stop()
Stop stops the agent loop, in case Start() was called.
func (*Anagent) Timer ¶
func (a *Anagent) Timer(tid TimerID, ti time.Time, after time.Duration, recurring bool, handler Handler) TimerID
Timer is used to set a generic timer. You have to supply by yourself all the options that normally are exposed with other functions. It requires a TimerID (if empty is supplied, it is created for you), a time.Time indicating when the timer have to be fired, a time.Duration indicating the recurring span a boolean to set it as recurring or not and at the end the callback to be fired at the desired time.
func (*Anagent) TimerSeconds ¶
TimerSeconds is used to set a timer, that will fire after the seconds supplied. It requires seconds supplied as int64 a bool indicating if it is recurring or not, and at the end the callback to be fired at the desired time.
type Handler ¶
type Handler interface{}
Handler can be any callable function. Anagent attempts to inject services into the handler's argument list, and panics if an argument could not be fulfilled via dependency injection.