source: perl/lib/BarnOwl/Timer.pm @ c6adf17

release-1.7release-1.8release-1.9
Last change on this file since c6adf17 was c6adf17, checked in by David Benjamin <davidben@mit.edu>, 11 years ago
Track names along with timers, add :show timers This will help people with BarnOwls eating CPU to diagnose timer leaks.
  • Property mode set to 100644
File size: 922 bytes
RevLine 
[ee183be]1use strict;
2use warnings;
3
4package BarnOwl::Timer;
5
6sub new {
7    my $class = shift;
8    my $args = shift;
9
10    my $cb = $args->{cb};
11    die("Invalid callback pased to BarnOwl::Timer\n") unless ref($cb) eq 'CODE';
12
13    my $self = {cb => $cb};
14
[c6adf17]15    my $name = $args->{name};
16    $name = "(unnamed)" unless defined $name;
17
[ee183be]18    bless($self, $class);
19
20    $self->{timer} = BarnOwl::Internal::add_timer($args->{after} || 0,
21                                                  $args->{interval} || 0,
[c6adf17]22                                                  $self,
23                                                  $name);
[ee183be]24    return $self;
25}
26
[8d16e58]27sub stop {
28    my $self = shift;
29    if(defined($self->{timer})) {
30        BarnOwl::Internal::remove_timer($self->{timer});
31        undef $self->{timer};
32    }
33}
34
[ee183be]35sub do_callback {
36    my $self = shift;
37    $self->{cb}->($self);
38}
39
40sub DESTROY {
41    my $self = shift;
[8d16e58]42    $self->stop;
[ee183be]43}
44
45
461;
Note: See TracBrowser for help on using the repository browser.