Closed le-garff-yoann closed 8 years ago
#!/usr/bin/env perl
use AnyEvent;
use Data::Dumper q/Dumper/;
my $cv = AnyEvent->condvar();
my @jobs;
my $adder; $adder = AnyEvent->timer( # add()
interval => 2,
cb => sub {
push @jobs, AnyEvent->timer(
interval => 3,
cb => sub {
warn "Hey i'm a job !\n";
}
)
}
);
my $cleaner; $cleaner = AnyEvent->timer( # delete()
interval => 15,
cb => sub {
@jobs = ();
}
);
my $watcher; $watcher = AnyEvent->timer(
interval => 1,
cb => sub {
warn @jobs . "\n";
}
);
$cv->recv();
New classes : Navel::AnyEvent::Pool
and Navel::AnyEvent::Pool::Timer
.
#!/usr/bin/env perl
use warnings;
use strict;
use AnyEvent;
use Navel::AnyEvent::Pool;
use Navel::Logger;
my $pool = Navel::AnyEvent::Pool->new(
logger => Navel::Logger->new(
severity => 'debug'
),
splay_limit => 5
);
$pool->attach_timer(
name => 'logger_0',
singleton => 1,
interval => 1,
callback => sub {
$pool->{logger}->flush_queue();
}
);
for my $timer_name (map { 'foo_' . $_ } 0..100) {
$pool->attach_timer(
name => $timer_name,
singleton => 1,
interval => 1,
enable => 0,
callback => sub {
warn $timer_name;
}
);
}
AnyEvent->condvar()->recv();
85078f7570541ae8fdbece197d8786523b546365
Move from
AnyEvent::Datetime::Cron
, use the simple "timer" ofAnyEvent
.Manage a pool of jobs in
Navel::Scheduler::Core
.