/usr/share/doc/libanyevent-xmpp-perl/examples/EVQ.pm is in libanyevent-xmpp-perl 0.55-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | package EVQ;
use strict;
use AnyEvent;
my $J;
our %reqh;
our $id = 0;
my @req;
sub schedule {
my $reqcnt = scalar (keys %reqh);
if ($reqcnt == 0 && !@req) {
warn "no more jobs, finishing...\n";
$J->broadcast;
}
while ($reqcnt < 200) {
my $r = pop @req;
return unless defined $r;
eval {
$r->[0]->(addreq ($r->[1]));
};
if ($@) { warn "EXCEPTION: $@\n" }
$reqcnt = scalar (keys %reqh);
}
}
sub addreq { my $k = $id . "_" . $_[0]; $reqh{$k} = 1; $id++; $k }
sub finreq { delete $reqh{$_[0]}; }
sub push_request {
my ($s, $cb) = @_;
push @req, [$cb, $s];
schedule;
}
our $t;
sub timer {
$t = AnyEvent->timer (after => 1, cb => sub {
schedule;
my $reqcnt = scalar (keys %reqh);
$reqcnt += @req;
my $rreqcnt = scalar (keys %reqh);
warn "$reqcnt outstanding requests [$rreqcnt in progress]\n";
timer ();
});
}
sub start {
$J = AnyEvent->condvar;
timer;
}
sub wait {
$J->wait;
}
1
|