Best pick for time-based 'event' looping?
Paul LeoNerd Evans
leonerd at leonerd.org.uk
Thu Apr 16 11:00:30 BST 2009
On Wed, 15 Apr 2009 18:16:56 -0700
"Randy J. Ray" <rjray at blackperl.com> wrote:
> 1. Init job queue
> 2. Add first task, which should happen immediately
> 3. (Loop starts here) Queue/Event-handler knows how long it has to
> wait before peeling the next task off the head of the queue and
> processing it.
> 4. Task runs, might insert some new, different tasks with their
> own offset-from-now values expressed in seconds. For example, the
> main task re-inserts itself to run again in 15 minutes, after it
> has checked a certain RSS feed for Last-Updated and possibly read
> it and parsed it.
> 5. Loop back to #3
> 6. Profit (this step is never actually reached)
IO::Async could make easy work of that
http://search.cpan.org/~pevans/IO-Async-0.19/lib/IO/Async.pm
specifically, you'll be wanting something like
use IO::Async::Loop;
my $loop = IO::Async::Loop->new();
sub take_over_world
{
print "Same thing we do every day Pinky...\n";
$loop->enqueue_timer(
delay => 3, # in seconds
code => sub { take_over_world() },
);
}
take_over_world();
$loop->loop_forever;
--
Paul "LeoNerd" Evans
leonerd at leonerd.org.uk
ICQ# 4135350 | Registered Linux# 179460
http://www.leonerd.org.uk/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://london.pm.org/pipermail/london.pm/attachments/20090416/912efb75/signature.pgp
More information about the london.pm
mailing list