]>
jfr.im git - irc/SurrealServices/srsv.git/blob - tags/0.4.3.1-pre2/SrSv/Timer.pm
1 # This file is part of SurrealServices.
3 # SurrealServices is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # SurrealServices is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with SurrealServices; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 use Exporter
'import';
22 BEGIN { our @EXPORT_OK = qw(add_timer begin_timer stop_timer) }
27 use SrSv
::Process
::InParent
qw(_add_timer stop_timer);
28 use SrSv
::Message
qw(message add_callback);
34 TRIGGER_COND
=> { CLASS
=> 'TIMER' },
35 CALL
=> 'SrSv::Timer::call',
39 add_timer
('hello', 2, __PACKAGE__
, 'SrSv::Timer::test');
40 sub test
{ ircd
::privmsg
('ServServ', '#surrealchat', $_[0]) };
44 my ($token, $delay, $owner, $callback) = @_;
46 if($callback !~ /::/) {
47 $callback = caller() . "::$callback";
50 _add_timer
($token, $delay, $owner, $callback);
54 my ($token, $delay, $owner, $callback) = @_;
56 push @{ $timers[$delay] }, [$token, $owner, $callback];
60 $timer_watcher = Event-
>timer(interval
=> 1, cb
=> \
&trigger
);
64 $timer_watcher->cancel if $timer_watcher;
68 my $timers = shift @timers;
70 foreach my $timer (@$timers) {
75 REALCALL
=> $timer->[2],
76 CALL
=> 'SrSv::Timer::call'
83 my ($message, $callback) = @_;
85 &{$message->{REALCALL
}}($message->{TOKEN
});