- Extended by:
- Defined in:
Simple timer services for Eventboxes
This module can be included into Eventbox classes to add simple timer functions.
class MyBox < include ::Timer async_call def init super # Make sure Timer#init is called timer_after(1) do puts "one second elapsed" end end end MyBox.new # Schedule the alarm after 1 sec sleep 2 # Wait for the timer to be triggered
The main functions are timer_after and timer_every. They schedule asynchronous calls to the given block:
timer_after(3.0) do # executed once after 3 seconds end timer_every(1.5) do # executed repeatedly every 1.5 seconds end
Both functions return anobject which can be used to cancel the alarm through timer_cancel.
event scope, in actions and from external scope. Alarms defined within the event scope must be non-blocking, as any other code in the event scope. Alarms defined in action or external scope should also avoid blocking code, otherwise one alarm can delay the next alarm.always uses one thread per Eventbox object, regardless of the number of scheduled timers. All alarms are called from this thread. timer_after, timer_every and timer_cancel can be used within the
Note: Each object that includes themodule must be explicit terminated by . It is (currently) not freed by the garbarge collector.
Defined Under Namespace
Classes:, , , ,
Methods included from
, , , , , ,