2 # Polled Timer handling
4 # This uses callbacks. BE CAREFUL!!!!
8 # Copyright (c) 2001 Dirk Koopman G1TLH
13 use vars qw(@timerchain $notimers $lasttime);
19 use vars qw($VERSION $BRANCH);
20 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
21 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0));
22 $main::build += $VERSION;
23 $main::branch += $BRANCH;
29 my ($pkg, $time, $proc, $recur) = @_;
31 my $class = $obj || $pkg;
32 my $self = bless { t=>$time + time, proc=>$proc }, $class;
33 $self->{interval} = $time if $recur;
34 push @timerchain, $self;
36 dbg("Timer created ($notimers)") if isdbg('connll');
44 @timerchain = grep {$_ != $self} @timerchain;
51 return unless $now != $lasttime;
53 # handle things on the timer chain
55 foreach $t (@timerchain) {
56 if ($now >= $t->{t}) {
58 $t->{t} = $now + $t->{interval} if exists $t->{interval};
67 dbg("timer destroyed ($Timer::notimers)") if isdbg('connll');