view release on metacpan or search on metacpan
--lib
--color
--failures
--recurse
--merge
--timer
--trap
view all matches for this distribution
view release on metacpan or search on metacpan
t/samples/mlpack-3.0.0/parse_command_line.hpp view on Meta::CPAN
// Add default parameters that are included in every program.
PARAM_FLAG("help", "Default help info.", "h");
PARAM_STRING_IN("info", "Get help on a specific module or option.", "", "");
PARAM_FLAG("verbose", "Display informational messages and the full list of "
"parameters and timers at the end of execution.", "v");
PARAM_FLAG("version", "Display the version of mlpack.", "V");
/**
* Parse the command line, setting all of the options inside of the CLI object
* to their appropriate given values.
view all matches for this distribution
view release on metacpan or search on metacpan
t/ansible-test1/ansible.cfg view on Meta::CPAN
## this is done to avoid running all of a type by default.
## These setting lists those that you want enabled for your system.
## Custom plugins should not need this unless plugin author specifies it.
# enable callback plugins, they can output to stdout but cannot be 'stdout' type.
#callback_whitelist = timer, mail
# Determine whether includes in tasks and handlers are "static" by
# default. As of 2.0, includes are dynamic by default. Setting these
# values to True will make includes behave more like they did in the
# 1.x versions.
view all matches for this distribution
view release on metacpan or search on metacpan
t/01_simple.t view on Meta::CPAN
is($payload, '{"foo":"bar"}', 'payload ok');
});
undef $apns;
my $t; $t = AnyEvent->timer(
after => 0.5,
cb => sub {
undef $t;
is $connect_state, 'disconnected', 'disconnected ok';
$cv->send;
view all matches for this distribution
view release on metacpan or search on metacpan
lib/AnyEvent/AggressiveIdle.pm view on Meta::CPAN
You want to stop idle calls until You have done Your work, You can hold
guard inside Your process:
aggressive_idle {
my ($pid, $guard) = @_;
my $timer;
$timer = AE::timer 0.5, 0 => sub {
undef $timer;
undef $guard; # POINT 1
}
}
Until 'B<POINT 1>' aggressive_idle won't call its callback.
view all matches for this distribution
view release on metacpan or search on metacpan
lib/AnyEvent/Beanstalk/Worker.pm view on Meta::CPAN
$_->($event) for @{$watchers{$event->{type}}};
}
The C<@events> list (or queue, since events are read as a FIFO) might
be populated asynchronously from system events, such as receiving
signals, network data, disk I/O, timers, or other sources. The
C<handle()> subroutine checks the C<%watchers> hash to see if there
are any watchers or handlers for this event and calls those
subroutines as needed. Some of these subroutines may add more events
to the event queue. Then the loop starts again.
view all matches for this distribution
view release on metacpan or search on metacpan
lib/AnyEvent/BitTorrent.pm view on Meta::CPAN
|| return;
flock($s->files->[$i]->{fh}, LOCK_SH) || return;
weaken $s unless isweak $s;
my $x = $i;
$s->files->[$x]->{timeout}
= AE::timer(500, 0, sub { $s // return; $s->_open($x, 'c') });
}
elsif ($m eq 'w') {
AE::log trace => 'Opening %s to write', $s->files->[$i]->{path};
my @split = File::Spec->splitdir($s->files->[$i]->{path});
pop @split; # File name itself
lib/AnyEvent/BitTorrent.pm view on Meta::CPAN
if -s $s->files->[$i]->{fh}
!= $s->files->[$i]->{length}; # XXX - pre-allocate files
weaken $s unless isweak $s;
my $x = $i;
$s->files->[$x]->{timeout}
= AE::timer(60, 0, sub { $s // return; $s->_open($x, 'c') });
}
elsif ($m eq 'c') { $s->files->[$i]->{timeout} = () }
else {return}
return $s->files->[$i]->{mode} = $m;
}
lib/AnyEvent/BitTorrent.pm view on Meta::CPAN
'Read %d bytes of data from file (%d bytes collected so far)',
length $_data, length $data;
weaken $s unless isweak $s;
my $x = $file_index;
$s->files->[$x]->{timeout}
= AE::timer(500, 0, sub { $s // return; $s->_open($x, 'c') });
}
$file_index++;
$length -= $this_read;
AE::log
trace => 'Still need to read %d bytes',
lib/AnyEvent/BitTorrent.pm view on Meta::CPAN
trace => 'Wrote %d bytes of data to file (%d bytes left)',
$w, length $data;
weaken $s unless isweak $s;
my $x = $file_index;
$s->files->[$x]->{timeout}
= AE::timer(120, 0, sub { $s // return; $s->_open($x, 'c') });
}
$file_index++;
last WRITE if not defined $s->files->[$file_index];
$total_offset = 0;
}
lib/AnyEvent/BitTorrent.pm view on Meta::CPAN
remote_interested => 0,
remote_requests => [],
local_choked => 1,
local_interested => 0,
local_requests => [],
timeout => AE::timer(20, 0, sub { $s->_del_peer($h) }),
keepalive => AE::timer(
30, 120,
sub {
$s->_send_encrypted($h, build_keepalive());
}
),
lib/AnyEvent/BitTorrent.pm view on Meta::CPAN
complete => 0,
incomplete => 0,
peers => '',
peers6 => '',
announcer => undef,
ticker => AE::timer(
1,
15 * 60,
sub {
return if $s->state eq 'stopped';
$s->announce('started');
lib/AnyEvent/BitTorrent.pm view on Meta::CPAN
= compact_ipv6(
uncompact_ipv6($tier->{peers6} . $reply->{peers6}))
if $reply->{peers6};
$tier->{complete} = $reply->{complete};
$tier->{incomplete} = $reply->{incomplete};
$tier->{ticker} = AE::timer(
$reply->{interval} // (15 * 60),
$reply->{interval} // (15 * 60),
sub {
return if $s->state eq 'stopped';
$s->_announce_tier($e, $tier);
lib/AnyEvent/BitTorrent.pm view on Meta::CPAN
push @{$tier->{urls}}, shift @{$tier->{urls}};
$s->_announce_tier($e, $tier);
}
}
}
has _choke_timer => (
is => 'bare',
isa => Ref,
init_arg => undef,
required => 1,
default => sub {
my $s = shift;
AE::timer(
15, 45,
sub {
return if $s->state ne 'active';
AE::log trace => 'Choke timer...';
my @interested
= grep { $_->{remote_interested} && $_->{remote_choked} }
values %{$s->peers};
# XXX - Limit the number of upload slots
lib/AnyEvent/BitTorrent.pm view on Meta::CPAN
# XXX - Send choke to random peer
}
);
}
);
has _fill_requests_timer => (
is => 'bare',
isa => Ref,
init_arg => undef,
required => 1,
default => sub {
my $s = shift;
AE::timer(
15, 10,
sub { # XXX - Limit by time/bandwidth
return if $s->state ne 'active';
AE::log trace => 'Request fill timer...';
my @waiting
= grep { defined && scalar @{$_->{remote_requests}} }
values %{$s->peers};
return if !@waiting;
my $total_sent = 0;
lib/AnyEvent/BitTorrent.pm view on Meta::CPAN
$s->_set_uploaded($s->uploaded + $total_sent);
}
);
}
);
has _peer_timer => (is => 'ro',
lazy => 1,
isa => Ref,
init_arg => undef,
clearer => '_clear_peer_timer',
builder => '_build_peer_timer'
);
sub _build_peer_timer {
my $s = shift;
AE::timer(
1, 15,
sub {
return if !$s->_left;
AE::log trace => 'Attempting to connect to new peer...';
lib/AnyEvent/BitTorrent.pm view on Meta::CPAN
if $packet->{payload}[1] ne $s->infohash;
$s->peers->{$h}{peerid} = $packet->{payload}[2];
$s->_send_handshake($h);
$s->_send_bitfield($h);
$s->peers->{$h}{timeout}
= AE::timer(60, 0, sub { $s->_del_peer($h) });
$s->peers->{$h}{bitfield} = pack 'b*', (0 x $s->piece_count);
$h->on_read(sub { $s->_on_read(@_) });
}
else { # This should never happen
}
lib/AnyEvent/BitTorrent.pm view on Meta::CPAN
return $s->_del_peer($h)
if $packet->{payload}[1] ne $s->infohash;
$s->peers->{$h}{peerid} = $packet->{payload}[2];
$s->_send_bitfield($h);
$s->peers->{$h}{timeout}
= AE::timer(60, 0, sub { $s->_del_peer($h) });
$s->peers->{$h}{bitfield} = pack 'b*', (0 x $s->piece_count);
}
elsif ($packet->{type} == $INTERESTED) {
$s->peers->{$h}{remote_interested} = 1;
}
lib/AnyEvent/BitTorrent.pm view on Meta::CPAN
$s->_consider_peer($s->peers->{$h});
}
elsif ($packet->{type} == $UNCHOKE) {
$s->peers->{$h}{local_choked} = 0;
$s->peers->{$h}{timeout}
= AE::timer(120, 0, sub { $s->_del_peer($h) });
$s->_request_pieces($s->peers->{$h});
}
elsif ($packet->{type} == $HAVE) {
vec($s->peers->{$h}{bitfield}, $packet->{payload}, 1) = 1;
$s->_consider_peer($s->peers->{$h});
$s->peers->{$h}{timeout}
= AE::timer(60, 0, sub { $s->_del_peer($h) });
}
elsif ($packet->{type} == $BITFIELD) {
$s->peers->{$h}{bitfield} = $packet->{payload};
$s->_consider_peer($s->peers->{$h});
}
elsif ($packet->{type} == $REQUEST) {
$s->peers->{$h}{timeout}
= AE::timer(120, 0, sub { $s->_del_peer($h) });
# XXX - Make sure (index + offset + length) < $s->size
# if not, send reject if remote supports fast ext
# either way, ignore the request
push @{$s->peers->{$h}{remote_requests}}, $packet->{payload};
}
elsif ($packet->{type} == $PIECE) {
$s->peers->{$h}{timeout}
= AE::timer(120, 0, sub { $s->_del_peer($h) });
my ($index, $offset, $data) = @{$packet->{payload}};
# Make sure $index is a working piece
$s->working_pieces->{$index} // return;
lib/AnyEvent/BitTorrent.pm view on Meta::CPAN
}
elsif ($packet->{type} == $HAVE_ALL) {
$s->peers->{$h}{bitfield} = pack 'b*', (1 x $s->piece_count);
$s->_consider_peer($s->peers->{$h});
$s->peers->{$h}{timeout}
= AE::timer(120, 0, sub { $s->_del_peer($h) });
}
elsif ($packet->{type} == $HAVE_NONE) {
$s->peers->{$h}{bitfield} = pack 'b*', (0 x $s->piece_count);
$s->peers->{$h}{timeout}
= AE::timer(30, 0, sub { $s->_del_peer($h) });
}
elsif ($packet->{type} == $REJECT) {
my ($index, $offset, $length) = @{$packet->{payload}};
return # XXX - error callback if this block is not in the queue
if !grep {
lib/AnyEvent/BitTorrent.pm view on Meta::CPAN
|| ($_->[1] != $offset)
|| ($_->[2] != $length)
} @{$s->peers->{$h}{local_requests}}
];
$s->peers->{$h}{timeout}
= AE::timer(30, 0, sub { $s->_del_peer($h) });
}
elsif ($packet->{type} == $ALLOWED_FAST) {
push @{$s->peers->{$h}{local_allowed}}, $packet->{payload};
}
else {
lib/AnyEvent/BitTorrent.pm view on Meta::CPAN
; # XXX - len for last piece
$s->working_pieces->{$index}{$offset} = [
$index, $offset,
$_block_size,
$p, undef,
AE::timer(
60, 0,
sub {
$p // return;
$p->{handle} // return;
$s->_send_encrypted($p->{handle},
lib/AnyEvent/BitTorrent.pm view on Meta::CPAN
$_->[0] != $index
|| $_->[1] != $offset
|| $_->[2] != $_block_size
} @{$p->{local_requests}}
];
$p->{timeout} = AE::timer(45, 0,
sub { $s->_del_peer($p->{handle}) });
#$s->_request_pieces( $p) # XXX - Ask a different peer
}
)
lib/AnyEvent/BitTorrent.pm view on Meta::CPAN
AE::log trace => 'Announcing "stopped" event to trackers...';
$s->announce('stopped');
AE::log trace => 'Disconnecting peers...';
$s->_clear_peers;
AE::log trace => 'Stopping new peers ticker...';
$s->_clear_peer_timer;
AE::log trace => 'Closing files...';
$s->_open($_, 'c') for 0 .. $#{$s->files};
AE::log trace => 'Setting internal status...';
$s->_set_state('stopped');
}
lib/AnyEvent/BitTorrent.pm view on Meta::CPAN
my $s = shift;
AE::log debug => 'Starting...';
$s->announce('started') unless $s->state eq 'active';
$s->peers;
AE::log trace => 'Starting new peers ticker...';
$s->_peer_timer;
AE::log trace => 'Setting internal status...';
$s->_set_state('active');
}
sub pause {
my $s = shift;
AE::log debug => 'Pausing...';
$s->peers;
AE::log trace => 'Starting new peers ticker...';
$s->_peer_timer;
AE::log trace => 'Setting internal status...';
$s->_set_state('paused');
}
#
sub BUILD {
view all matches for this distribution
view release on metacpan or search on metacpan
lib/AnyEvent/Blackboard.pm view on Meta::CPAN
=over 4
=item timeout SECONDS, [ KEY, [, DEFAULT ] ]
Set a timer for N seconds to provide "default" value as a value, defaults to
`undef`. This can be used to ensure that blackboard workflows do not reach a
dead-end if a required value is difficult to obtain.
=cut
lib/AnyEvent/Blackboard.pm view on Meta::CPAN
my ($self, $seconds, $key, $default) = @_;
$key = [ $key ] unless (ref $key eq "ARRAY");
unless ($self->has($key)) {
my $guard = AnyEvent->timer(
after => $seconds,
cb => sub {
unless ($self->has($key)) {
$self->put($_ => $default) for @$key;
}
}
);
# Cancel the timer if we find the object first (otherwise this is a NOOP).
$self->_watch($key, sub { undef $guard });
}
}
=item watch KEYS, WATCHER [, KEYS, WATCHER ]
view all matches for this distribution
view release on metacpan or search on metacpan
lib/AnyEvent/CacheDNS.pm view on Meta::CPAN
? $DEFAULT_TTL
: ($IS_AE_6X && @_ ? int($_[0]->[3] || 0) : 0)
;
if ($ttl > 0) {
# Create expire timer
my $wt;
$wt = AE::timer($ttl, 0, sub {
$wt = undef;
delete($cache->{$qname});
});
}
view all matches for this distribution
view release on metacpan or search on metacpan
t/030-ae-cbs.t view on Meta::CPAN
}
for my $cv (AE::cv) {
my @res;
my $cbs = CBS;
my @timers;
for (1 .. 10) {
push @timers => AE::timer rand .1, 0, $cbs->cb;
}
push @timers => AE::timer 0, 0, $cbs->cb;
$cbs->wait(sub { @res = @_; $cv->send });
{
$cbs->cb;
view all matches for this distribution
view release on metacpan or search on metacpan
my $time = AE::now;
$SIG{'ALRM'} = sub { die };
eval {
alarm(1);
capture { AE::timer 0.5, 0, shift };
alarm(0);
};
if ($@) {
fail("We slept successfully");
diag(" We hadn't woken up after a second and an alarm triggered");
view all matches for this distribution
view release on metacpan or search on metacpan
lib/AnyEvent/Chromi.pm view on Meta::CPAN
{
my ($self) = @_;
$log->info("connection failed. reconnecting in 1 second");
$self->{conn_w} = AnyEvent->timer (after => 1, cb => sub {
$self->_start_client();
});
}
sub _start_client
view all matches for this distribution
view release on metacpan or search on metacpan
lib/AnyEvent/Collect.pm view on Meta::CPAN
use AnyEvent::Collect;
# Wait for all of a collection of events to trigger once:
my( $w1, $w2 );
collect {
$w1 = AE::timer 2, 0, event { say "two" };
$w2 = AE::timer 3, 0, event { say "three" };
}; # Returns after 3 seconds having printed "two" and "three"
# Wait for any of a collection of events to trigger:
my( $w3, $w4 );
collect_any {
$w3 = AE::timer 2, 0, event { say "two" };
$w4 = AE::timer 3, 0, event { say "three" };
};
# Returns after 2 seconds, having printed 2. Note however that
# the other event will still be emitted in another second. If
# you were to then execute the sleep below, it would print three.
view all matches for this distribution
view release on metacpan or search on metacpan
lib/AnyEvent/ConnPool.pm view on Meta::CPAN
for (1 .. $conn_count) {
$self->add();
}
if ($self->{check}) {
my $guard; $guard = AnyEvent->timer (
after => $self->{check}->{interval},
interval => $self->{check}->{interval},
cb => sub {
my $temp_guard = $guard;
for (my $i = 0; $i < $self->{count}; $i++) {
view all matches for this distribution
view release on metacpan or search on metacpan
lib/AnyEvent/Connection.pm view on Meta::CPAN
Close current connection and establish a new one
=item after($interval, $cb->())
Helper method. AE::timer(after), associated with current connection
Will be destroyed if connection is destroyed, so no timer invocation after connection destruction.
=item periodic($interval, $cb->())
Helper method. AE::timer(periodic), associated with current connection
Will be destroyed if connection is destroyed, so no timer invocation after connection destruction.
=item periodic_stop()
If called within periodic callback, periodic will be stopped.
lib/AnyEvent/Connection.pm view on Meta::CPAN
# callback will be called only 10 times;
=item destroy
Close connection, destroy all associated objects and timers, clean self
=back
=head1 CONNECT METHODS
lib/AnyEvent/Connection.pm view on Meta::CPAN
$self->{debug} ||= 0;
$self->{connected} = 0;
$self->{connecting} = 0;
$self->{reconnect} = 1 unless defined $self->{reconnect};
$self->{timeout} ||= 3;
$self->{timers} = {};
$self->{rawcon} ||= 'AnyEvent::Connection::Raw';
#warn "Init $self";
}
#sub connected {
lib/AnyEvent/Connection.pm view on Meta::CPAN
sub _reconnect_after {
weaken( my $self = shift );
$self->{reconnect} or return $self->{connecting} = 0;
$self->{timers}{reconnect} = AnyEvent->timer(
after => $self->{reconnect},
cb => sub {
$self or return;
delete $self->{timers}{reconnect};
$self->{connecting} = 0;
$self->connect;
}
);
}
lib/AnyEvent/Connection.pm view on Meta::CPAN
sub periodic {
weaken( my $self = shift );
my $interval = shift;
my $cb = shift;
#warn "Create periodic $interval";
$self->{timers}{int $cb} = AnyEvent->timer(
after => $interval,
interval => $interval,
cb => sub {
local *periodic_stop = sub {
warn "Stopping periodic ".int $cb;
delete $self->{timers}{int $cb}; undef $cb
};
$self or return;
$cb->();
},
);
defined wantarray and return AnyEvent::Util::guard(sub {
delete $self->{timers}{int $cb};
undef $cb;
});
return;
}
sub after {
weaken( my $self = shift );
my $interval = shift;
my $cb = shift;
#warn "Create after $interval";
$self->{timers}{int $cb} = AnyEvent->timer(
after => $interval,
cb => sub {
$self or return;
delete $self->{timers}{int $cb};
$cb->();
undef $cb;
},
);
defined wantarray and return AnyEvent::Util::guard(sub {
delete $self->{timers}{int $cb};
undef $cb;
});
return;
}
lib/AnyEvent/Connection.pm view on Meta::CPAN
delete $self->{con};
my $wascon = $self->{connected} || $self->{connecting};
$self->{connected} = 0;
$self->{connecting} = 0;
#$self->{reconnect} = 0;
delete $self->{timers}{reconnect};
$self->event('disconnect',@_) if $wascon;
return;
}
sub AnyEvent::Connection::destroyed::AUTOLOAD {}
view all matches for this distribution
view release on metacpan or search on metacpan
lib/AnyEvent/Consul/Exec.pm view on Meta::CPAN
sub _start_session {
my ($self) = @_;
my $session_started_cb = sub {
$self->{_sid} = shift;
$self->{_refresh_guard} = AnyEvent->timer(after => "5s", interval => "5s", cb => sub {
$self->{_c}->session->renew(
$self->{_sid},
$self->{dc_args}->@*,
);
});
view all matches for this distribution
view release on metacpan or search on metacpan
lib/AnyEvent/CouchDB/Stream.pm view on Meta::CPAN
{
Scalar::Util::weaken( my $self = $self );
my $set_timeout = $timeout
? sub {
$self->{timeout}
= AE::timer( $timeout, 0, sub { $on_error->('timeout') } );
}
: sub { };
$set_timeout->();
view all matches for this distribution
view release on metacpan or search on metacpan
lib/AnyEvent/Cron.pm view on Meta::CPAN
default => sub { [ ] }
;
has timers => ( is => 'rw', isa => 'ArrayRef' , default => sub { [ ] } );
use Scalar::Util qw(refaddr);
sub add {
my $self = shift;
lib/AnyEvent/Cron.pm view on Meta::CPAN
}
}
}
$job->{next}{ $next_epoch } = 1;
$job->{watchers}{$next_epoch} = AnyEvent->timer(
after => $delay,
cb => sub {
$self->{_cv}->begin;
delete $job->{watchers}{$next_epoch};
view all matches for this distribution
view release on metacpan or search on metacpan
lib/AnyEvent/Curl/Multi.pm view on Meta::CPAN
my $class = shift;
my $self = $class->SUPER::new(
multi_h => WWW::Curl::Multi->new,
state => {},
timer_w => undef,
io_w => {},
queue => [],
max_concurrency => 0,
max_redirects => 0,
timeout => undef,
lib/AnyEvent/Curl/Multi.pm view on Meta::CPAN
} else {
last;
}
}
# Start our timer
$self->{timer_w} = AE::timer(0, 0.5, sub { $self->_perform });
}
sub _perform {
my $self = shift;
lib/AnyEvent/Curl/Multi.pm view on Meta::CPAN
# We must recalculate the number of active handles here, because
# a user-provided callback may have added a new one.
my $active_handles = scalar keys %{$self->{state}};
if (! $active_handles) {
# Nothing left to do - no point keeping the watchers around anymore.
delete $self->{timer_w};
delete $self->{io_w};
return;
}
# Re-establish all I/O watchers
view all matches for this distribution
view release on metacpan or search on metacpan
t/02-timeouts.t view on Meta::CPAN
discard_timeout => 0.5,
callback => sub { $cv->send($_[0]) });
my $msg = $cv->recv;
is($msg->value, 1380, 'first value');
$cv = AnyEvent->condvar;
AnyEvent->timer(after => 1.5, sub { $cv->send });
warning_like { $msg = $cv->recv }
{carped => qr/Discarding '<msg><src>truncated'/}, 'discard timeout';
is($msg->value, 1999, 'second value');
waitpid $pid, 0;
view all matches for this distribution
view release on metacpan or search on metacpan
eg/simple_daap_server.pl view on Meta::CPAN
use File::Basename qw(dirname);
my $daap = AnyEvent::DAAP::Server->new(port => 23689);
my %playlist;
my $w; $w = AE::timer 1, 0, sub {
foreach my $file (find name => "*.mp3", in => '.') {
my $dir = dirname $file;
my $playlist = $playlist{$dir} ||= do {
my $playlist = AnyEvent::DAAP::Server::Playlist->new(
dmap_itemname => $dir,
view all matches for this distribution
view release on metacpan or search on metacpan
lib/AnyEvent/DBD/Pg.pm view on Meta::CPAN
warn;
$cb->();
$self->_dequeue;
};
# At all we don't need timers for the work, but if we have some bugs, it will help us to find them
push @watchers, AE::timer 1,1, $watchers[0];
push @watchers, AE::io $self->{fh}, 0, $watchers[0];
$watchers[0]() and return;
return;
}
view all matches for this distribution
view release on metacpan or search on metacpan
$dbh->do('SELECT SLEEP(0.1)', sub {
ok 1, 'dbh1 callback fired';
undef $t[1];
NEXT();
});
$t[1] = AnyEvent->timer(after => 0.5, cb => sub {
ok 0, 'dbh1 callback fired';
delete $dbh{1};
NEXT();
});
},
$dbh->prepare('SELECT SLEEP(0.1)')->execute(sub {
ok 1, 'dbh2 callback fired';
undef $t[2];
NEXT();
});
$t[2] = AnyEvent->timer(after => 0.5, cb => sub {
ok 0, 'dbh2 callback fired';
delete $dbh{2};
NEXT();
});
},
$dbh->selectall_arrayref('SELECT SLEEP(0.1)', sub {
ok 1, 'dbh3 callback fired';
undef $t[3];
NEXT();
});
$t[3] = AnyEvent->timer(after => 0.5, cb => sub {
ok 0, 'dbh3 callback fired';
delete $dbh{3};
NEXT();
});
},
$dbh->do('SELECT SLEEP(0.1)', sub {
ok 0, 'dbh4 callback ignored';
undef $t[4];
NEXT();
});
$t[4] = AnyEvent->timer(after => 0.5, cb => sub {
ok 1, 'dbh4 callback ignored';
NEXT();
});
},
sub {
$dbh->prepare('SELECT SLEEP(0.1)')->execute(sub {
ok 0, 'dbh5 callback ignored';
undef $t[5];
NEXT();
});
$t[5] = AnyEvent->timer(after => 0.5, cb => sub {
ok 1, 'dbh5 callback ignored';
NEXT();
});
},
sub {
$dbh->selectall_arrayref('SELECT SLEEP(0.1)', sub {
ok 0, 'dbh6 callback ignored';
undef $t[6];
NEXT();
});
$t[6] = AnyEvent->timer(after => 0.5, cb => sub {
ok 1, 'dbh6 callback ignored';
NEXT();
});
},
sub {
view all matches for this distribution
view release on metacpan or search on metacpan
fork_template => $template;
=item timeout => seconds
If you supply a timeout parameter (fractional values are supported), then
a timer is started any time the DBI handle expects a response from the
server. This includes connection setup as well as requests made to the
backend. The timeout spans the duration from the moment the first data
is written (or queued to be written) until all expected responses are
returned, but is postponed for "timeout" seconds each time more data is
returned from the server. If the timer ever goes off then a fatal error is
generated. If you have an C<on_error> handler installed, then it will be
called, otherwise your program will die().
When altering your databases with timeouts it is wise to use
transactions. If you quit due to timeout while performing insert, update
$self->{rw} = AE::io $client, 0, sub {
my $len = Convert::Scalar::extend_read $client, $rbuf, 65536;
if ($len > 0) {
# we received data, so reset the timer
$self->{last_activity} = AE::now;
for my $res ($cbor->incr_parse_multiple ($rbuf)) {
last unless $self;
# we did time out
my $req = $self->{queue}[0];
$self->_error (timeout => $req->[1], $req->[2], 1); # timeouts are always fatal
} else {
# we need to re-set the timeout watcher
$self->{tw} = AE::timer
$self->{last_activity} + $self->{timeout} - AE::now,
0,
$self->{tw_cb},
;
}
sub timeout {
my ($self, $timeout) = @_;
$self->{timeout} = $timeout;
# reschedule timer if one was running
$self->{tw_cb}->();
}
sub _req {
my ($self, $cb, $filename, $line) = splice @_, 0, 4, ();
view all matches for this distribution
view release on metacpan or search on metacpan
# claim we are the main reactor mainloop
*Net::DBus::Reactor::main = sub { __PACKAGE__ };
our $I = 0;
our %O; # watchers and timers, unfortunately, dbus only supports attaching integers...
sub watch_off {
delete $O{$_[1]->get_data};
}
my ($con, $w) = @_;
my $id = $w->get_data;
my $i = $w->get_interval * 0.001;
$O{$id} = $w->is_enabled && AE::timer $i, $i, sub {
$w->handle;
$con->dispatch;
};
}
view all matches for this distribution
view release on metacpan or search on metacpan
lib/AnyEvent/DNS/Cache/Simple.pm view on Meta::CPAN
AnyEvent::DNS::Cache::Simple provides simple cache capability for AnyEvent::DNS
CPAN already has AnyEvent::CacheDNS module. It also provides simple cache.
AnyEvent::DNS::Cache::Simple support ttl, negative_ttl and can use with any cache module.
And AnyEvent::DNS::Cache::Simple does not use AnyEvent->timer for purging cache.
=head1 METHOD
=head2 register
view all matches for this distribution
view release on metacpan or search on metacpan
lib/AnyEvent/DateTime/Cron.pm view on Meta::CPAN
}
$self->{_cv}->end;
};
$job->{watchers}{$next_epoch} = AnyEvent->timer(
after => $delay,
cb => $run_event
);
}
}
view all matches for this distribution
view release on metacpan or search on metacpan
lib/AnyEvent/Debounce.pm view on Meta::CPAN
isa => 'Bool',
default => 0,
documentation => 'if true, trigger immediately after the first event is received',
);
has 'always_reset_timer' => (
is => 'ro',
isa => 'Bool',
default => 0,
documentation => 'if true, reset the timer after each event',
);
has 'delay' => (
is => 'ro',
isa => 'Num',
lib/AnyEvent/Debounce.pm view on Meta::CPAN
lazy => 1,
clearer => 'clear_queued_events',
handles => { 'queue_event' => 'push', 'event_count' => 'count' },
);
has 'timer' => (
reader => 'timer',
lazy_build => 1,
);
sub _build_timer {
my $self = shift;
return AnyEvent->timer(
after => $self->delay,
interval => 0,
cb => sub { $self->send_events_now },
);
}
sub send_events_now {
my $self = shift;
my $events = $self->queued_events;
my $count = $self->event_count;
$self->clear_timer;
$self->clear_queued_events;
$self->cb->(@$events) if $count > 0;
return;
}
sub send {
my ($self, @args) = @_;
my $timer_running = $self->has_timer;
$self->clear_timer if $self->always_reset_timer;
$self->timer; # resets the timer if we don't have one
if($self->front_triggered && !$timer_running){
$self->cb->([@args]);
}
elsif(!$self->front_triggered){
$self->queue_event([@args]);
}
lib/AnyEvent/Debounce.pm view on Meta::CPAN
=head1 delay
The time to wait after receiving an event before sending it, in case
more events happen in the interim.
=head1 always_reset_timer
Normally, when an event is received and it's the first of a series, a
timer is started, and when that timer expires, all events are sent.
If you set this initarg to a true value, then the timer is reset after
each event is received.
For example, if you set the delay to 1, and ten events arrive at 0.5
second intervals, then with this flag set to true, you will get one
event after 5 seconds. With this flag set to false, you will get an
lib/AnyEvent/Debounce.pm view on Meta::CPAN
C<delay> seconds, even if they occur. These events are lost, you will
never see them.
By default, this is false.
If you also set C<always_reset_timer> to true, the same timer-reset
logic as described above occurs.
=head1 METHODS
=head1 send
view all matches for this distribution
view release on metacpan or search on metacpan
lib/AnyEvent/Delay.pm view on Meta::CPAN
sub steps {
my $self = shift;
$self->{steps} = [@_];
$self->begin->();
#$self->{timers}{-1} = EV::timer 0, 0, $self->begin;
return $self;
}
sub _step {
my ($self, $id) = (shift, shift);
lib/AnyEvent/Delay.pm view on Meta::CPAN
if (! $self->{_ae_counter}) {
return $self->on_finish->( @args );
}
if (! $self->{pending}) {
$self->{timers}{$id} = EV::timer 0, 0, $self->begin
}
}
1;
lib/AnyEvent/Delay.pm view on Meta::CPAN
my $cv = AE::cv;
my $delay = AnyEvent::Delay->new();
$delay->on_finish(sub { say 'BOOM!'; $cv->send });
for my $i (1 .. 10) {
my $end = $delay->begin;
Mojo::IOLoop->timer($i => sub {
say 10 - $i;
$end->();
});
}
$cv->recv;
lib/AnyEvent/Delay.pm view on Meta::CPAN
$delay->steps(
# First step (parallel events)
sub {
my $delay = shift;
Mojo::IOLoop->timer(2 => $delay->begin);
http_get( 'http://www.yinyuetai.com' => $delay->begin );
say 'Second step in 2 seconds.';
},
# Second step (parallel timers)
sub {
my ($delay, @args) = @_;
say "This http response is $args[1]->[1]{Status}";
Mojo::IOLoop->timer(1 => $delay->begin);
Mojo::IOLoop->timer(3 => $delay->begin);
say 'Third step in 3 seconds.';
},
# Third step (the end)
sub {
view all matches for this distribution
view release on metacpan or search on metacpan
use AnyEvent; # not AE
# file handle or descriptor readable
my $w = AE::io $fh, 0, sub { ... };
# one-shot or repeating timers
my $w = AE::timer $seconds, 0, sub { ... }; # once
my $w = AE::timer $seconds, $interval, sub { ... }; # repeated
print AE::now; # prints current event loop time
print AE::time; # think Time::HiRes::time or simply CORE::time.
# POSIX signal
Example: wait until STDOUT becomes writable and print something.
$stdout_ready = AE::io *STDOUT, 1, sub { print STDOUT "woaw\n" };
=item $w = AE::timer $after, $interval, $cb
Creates a timer watcher that invokes the callback C<$cb> after at least
C<$after> second have passed (C<$after> can be negative or C<0>).
If C<$interval> is C<0>, then the callback will only be invoked once,
otherwise it must be a positive number of seconds that specifies the
interval between successive invocations of the callback.
Example: print "too late" after at least one second has passed.
$timer_once = AE::timer 1, 0, sub { print "too late\n" };
Example: print "blubb" once a second, starting as soon as possible.
$timer_repeated = AE::timer 0, 1, sub { print "blubb\n" };
=item $w = AE::signal $signame, $cb
Invoke the callback C<$cb> each time one or more occurrences of the
named signal C<$signame> are detected.
view all matches for this distribution