View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Paul Sturm > Tibco-Rv-1.15 > Tibco::Rv::Timer



Annotate this POD

View/Report Bugs
Module Version: 1.04   Source  


Tibco::Rv::Timer - Tibco Timer event object


   my ( $timer ) = $rv->createTimer( interval => 10, sub
      print "Timer event happened!\n";
   } );

   $timer->interval( 5 );

   $timer->onEvent( );


A Tibco::Rv::Timer fires an event after every specified interval. It is a subclass of Tibco::Rv::Event, so Event methods are available to Timers (documentation on Event methods are reproduced here for convenience).


$timer = new Tibco::Rv::Timer( %args )
      queue => $queue,
      interval => $interval,
      callback => sub { ... }

Creates a Tibco::Rv::Timer. If not specified, queue defaults to the Default Queue, interval defaults to 1, and callback defaults to:

   sub { print "Timer fired\n" }

Create a Timer to cause an event to fire after every $interval seconds. The $interval can specify fractions of a second. When $queue dispatches such an event, it triggers the given callback.


$interval = $timer->interval

Returns the number of seconds in the interval between firings of the Timer's event.

$timer->interval( $interval ) (or $timer->resetTimerInterval( $interval ))

Set the interval at which the next Timer event will be dispatched.

$queue = $timer->queue

Returns the queue on which this Timer's events will be dispatched.

$callback = $timer->callback

Returns the callback code reference.


Trigger an event directly. The event will be processed as if it was triggered via the event queue.


Cancels the Timer. Called automatically when $timer goes out of scope. Calling DESTROY more than once has no effect.


As an alternative to passing in a callback function to the constructor, there is another way to handle events. You can subclass Tibco::Rv::Timer and override the onEvent method, as follows:

   package MyTimer;
   use base qw/ Tibco::Rv::Timer /;

   sub new
      my ( $proto, %args ) = @_;
      my ( $self ) = $proto->SUPER::new( %args );
      # your initialization code
      return $self;

   sub onEvent
      my ( $self ) = @_;
      # process event here
      # $self->queue, $self->interval are available

   # any other implementation code for your class


The Tibco::Rv::Event onEvent method simply calls the callback, so overriding onEvent allows you to process the event however you want, and you can just not use the callback.

The advantages of this method of handling events are: it is more object-oriented; you have access to the queue and interval via the $self accessor methods; and, you can have more elaborate processing of timed events without having to shove it all into one callback.

You can use your subclassed Timer as follows:

   use Tibco::Rv;
   use MyTimer;

   my ( $rv ) = new Tibco::Rv;
   my ( $myTimer ) = new MyTimer( interval => 4 );


Paul Sturm <>

syntax highlighting: