Class Timer::Timer
In: lib/rbot/timer.rb
Parent: Object

timer handler, manage multiple Action objects, calling them when required. The timer must be ticked by whatever controls it, i.e. regular calls to tick() at whatever granularity suits your application’s needs.

Alternatively you can call run(), and the timer will spawn a thread and tick itself, intelligently shutting down the thread if there are no pending actions.

Methods

add   add_once   block   new   next_action_time   remove   run   running?   start   start_on_add   start_thread   stop   stop_thread   tick   unblock  

Public Class methods

Public Instance methods

period:how often (seconds) to run the action
data:optional data to pass to the action’s proc
func:associate a block with add() to perform the action

add an action to the timer

period:how long (seconds) until the action is run
data:optional data to pass to the action’s proc
func:associate a block with add() to perform the action

add an action to the timer which will be run just once, after period

block action with handle handle

return the number of seconds until the next action is due, or 0 if none are outstanding - will only be accurate immediately after a tick()

remove action with handle handle from the timer

for backwards compat - this is a bit primitive

start the timer, it spawns a thread to tick the timer, intelligently shutting down if no events remain and starting again when needed.

stop the timer from ticking

you can call this when you know you’re idle, or you can split off a thread and call the run() method to do it for you.

unblock action with handle handle

Private Instance methods

[Validate]