AnyEvent-Semaphore
view release on metacpan or search on metacpan
lib/AnyEvent/Semaphore.pm view on Meta::CPAN
sub running { shift->{running} }
sub down {
return unless defined $_[1];
my ($sem) = @_;
my $watchers = $sem->{watchers};
my $w = [@_];
bless $w, 'AnyEvent::Semaphore::Watcher';
push @{$watchers}, $w;
Scalar::Util::weaken($watchers->[-1]);
&AE::postpone($sem->{schedule_cb});
$w;
}
sub _schedule {
my $sem = shift;
my $watchers = $sem->{watchers};
while ($sem->{size} > $sem->{running}) {
if (defined (my $w = shift @$watchers)) {
$sem->{running}++;
lib/AnyEvent/Semaphore.pm view on Meta::CPAN
sub AnyEvent::Semaphore::Watcher::DESTROY {
local ($!, $@, $SIG{__DIE__});
eval {
my $watcher = shift;
my $sem = $watcher->[0];
my $holes = ++$sem->{holes};
my $watchers = $sem->{watchers};
if ($holes > 100 and $holes * 2 > @$watchers) {
@{$sem->{watchers}} = grep defined, @$watchers;
Scalar::Util::weaken $_ for @$watchers;
$sem->{holes} = 0;
}
}
}
sub AnyEvent::Semaphore::Down::DESTROY {
local ($!, $@, $SIG{__DIE__});
eval {
my $sem = shift->[0];
$sem->{running}--;
( run in 0.245 second using v1.01-cache-2.11-cpan-65fba6d93b7 )