Added timer_add() and timer_del() to API::Std for timers.
This commit is contained in:
1 parent
2acaef26e0
commit
159600b669
3 files changed
+64
-4
No files matched your search
@@ -77,7 +77,7 @@ API::Std::event_add("on_sighup");
|
||||
# Print startup message.
|
||||
println "* ".NAME." (version ".VER.".".SVER.".".REV.RSTAGE.") is starting up...";
|
||||
|
||||
our ($PID);
|
||||
our ($PID, %TIMERS);
|
||||
|
||||
# Check for debug mode.
|
||||
our $DEBUG = 0;
|
||||
@@ -208,8 +208,27 @@ else {
|
||||
}
|
||||
undef $it;
|
||||
|
||||
# Keep Auto alive.
|
||||
while (1) { sleep 1; }
|
||||
# Check timers.
|
||||
while (1) {
|
||||
foreach my $tk (keys %TIMERS) {
|
||||
if ($TIMERS{$tk}{time} <= time) {
|
||||
&{ $TIMERS{$tk}{sub} }();
|
||||
if ($TIMERS{$tk}{type} == 1) {
|
||||
# If it's type 1, delete from memory.
|
||||
delete $TIMERS{$tk};
|
||||
}
|
||||
elsif ($TIMERS{$tk}{type} == 2) {
|
||||
# If it's type 2, reset timer.
|
||||
$TIMERS{$tk}{time} = time + $TIMERS{$tk}{secs};
|
||||
}
|
||||
else {
|
||||
# This should never happen.
|
||||
delete $TIMERS{$tk};
|
||||
}
|
||||
}
|
||||
}
|
||||
sleep 1;
|
||||
}
|
||||
|
||||
###############
|
||||
# Subroutines #
|
||||
|
||||
Reference in new issue
Block a user