| 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.
| 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
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()
start the timer, it spawns a thread to tick the timer, intelligently shutting down if no events remain and starting again when needed.
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.