view release on metacpan or search on metacpan
lib/AnyEvent/PgRecvlogical.pm view on Meta::CPAN
has on_message => (is => 'ro', isa => CodeRef, required => 1);
has on_error => (is => 'ro', isa => CodeRef, default => sub { \&croak });
has _fh_watch => (is => 'lazy', isa => Ref, clearer => 1, predicate => 1);
has _timer => (is => 'lazy', isa => Ref, clearer => 1);
=head1 CONSTRUCTOR
All the L</"ATTRIBUTES"> above are accepted by the constructor, with a few exceptions:
lib/AnyEvent/PgRecvlogical.pm view on Meta::CPAN
}
return $w;
}
sub _build__timer {
my $self = shift;
if ($AnyEvent::MODEL and $AnyEvent::MODEL eq 'AnyEvent::Impl::EV') {
my $w = EV::periodic(0, $self->heartbeat, 0, $self->curry::weak::_heartbeat);
$w->priority(&EV::MAXPRI);
return $w;
} else {
return AE::timer $self->heartbeat, $self->heartbeat, $self->curry::weak::_heartbeat;
}
}
=head1 METHODS
lib/AnyEvent/PgRecvlogical.pm view on Meta::CPAN
=item 2. L</"create_slot"> (if requested)
=item 3. L</"start_replication">
=item 4. heartbeat timer
=back
This method wraps the above steps for convenience. Should you desire to modify the
L<replication startup protocol|https://www.postgresql.org/docs/current/static/protocol-replication.html> (which you
lib/AnyEvent/PgRecvlogical.pm view on Meta::CPAN
my ($self, $d) = @_;
return $d->then(
sub {
$self->_fh_watch;
$self->_timer;
},
$self->on_error,
);
}
lib/AnyEvent/PgRecvlogical.pm view on Meta::CPAN
sub stop {
my $self = shift;
$self->_clear_fh_watch;
$self->_clear_timer;
$self->clear_dbh;
}
sub _handle_disconnect {
my $self = shift;
lib/AnyEvent/PgRecvlogical.pm view on Meta::CPAN
$self->_set_startpos($self->flushed_lsn);
$self->clear_received_lsn;
$self->clear_flushed_lsn;
my $w; $w = AE::timer $self->reconnect_delay, 0, sub {
undef $w;
$self->_post_init(deferred { $self->start_replication });
};
}
lib/AnyEvent/PgRecvlogical.pm view on Meta::CPAN
my $d = deferred;
# no async operation in progress
return $d->reject if $dbh->{pg_async_status} == 0; # uncoverable branch true
my $w; $w = AE::timer 0, AWAIT_INTERVAL, sub {
return unless $dbh->pg_ready;
try {
$d->resolve($dbh->pg_result);
} catch {
$d->reject($_);
view all matches for this distribution
view release on metacpan or search on metacpan
lib/AnyEvent/Ping.pm view on Meta::CPAN
);
# Ping tasks
$self->{_tasks} = [];
$self->{_tasks_out} = [];
$self->{_timers} = {};
return $self;
}
sub interval { @_ > 1 ? $_[0]->{interval} = $_[1] : $_[0]->{interval} }
lib/AnyEvent/Ping.pm view on Meta::CPAN
sub end {
my $self = shift;
delete $self->{_poll_read};
delete $self->{_poll_write};
delete $self->{_timers};
while (my $request = pop @{$self->{_tasks}}) {
$request->{cb}->($request->{results});
}
lib/AnyEvent/Ping.pm view on Meta::CPAN
my ($self, $request, $result) = @_;
my $results = $request->{results};
# Clear request specific data
delete $self->{_timers}->{$request};
push @$results, [$result, time - $request->{start}];
if (@$results == $request->{times} || $result eq 'ERROR') {
lib/AnyEvent/Ping.pm view on Meta::CPAN
}
# Perform another check
else {
# Setup interval timer before next request
$self->{_timers}{$request} = AnyEvent->timer(
after => $self->interval,
cb => sub {
delete $self->{_timers}{$request};
push @{$self->{_tasks_out}}, $request;
$self->_add_write_poll;
}
);
}
lib/AnyEvent/Ping.pm view on Meta::CPAN
$request->{data} = $data;
$request->{start} = time;
$self->{_timers}->{$request}->{timer} = AnyEvent->timer(
after => $self->timeout,
cb => sub {
$self->_store_result($request, 'TIMEOUT');
}
);
view all matches for this distribution
view release on metacpan or search on metacpan
eg/stream.pl view on Meta::CPAN
while (my $req = $server->recv) {
$req->respond(sub {
my $respond = shift;
my $writer = $respond->([ 200, [ 'Content-Type' => 'text/plain' ] ]);
my $w; $w = AE::timer 1, 1, sub {
$writer->write(localtime . "\n");
scalar $w;
};
});
}
view all matches for this distribution
view release on metacpan or search on metacpan
lib/AnyEvent/Plurk.pm view on Meta::CPAN
$self->event("unread_plurks" => $unread_plurks);
$self->{__polling_time_offset} = current_time_offset;
}
}
$self->{__polling_timer} = AE::timer 60, 0, sub {
undef $self->{__polling_timer};
$self->_start_polling;
}
}
);
}
view all matches for this distribution
view release on metacpan or search on metacpan
lib/AnyEvent/Proc.pm view on Meta::CPAN
my $eol = quotemeta $self->_eol;
$self->{reol} = delete $options{reol} || qr{$eol};
}
if ( $options{ttl} ) {
$self->{timer} = AnyEvent->timer(
after => delete $options{ttl},
cb => sub {
return unless $self->alive;
$self->kill;
$self->_emit('ttl_exceed');
lib/AnyEvent/Proc.pm view on Meta::CPAN
$waiter->begin;
$cv->cb(
sub {
$self->{status} = shift->recv;
$self->{alive} = 0;
undef $self->{timer};
$waiter->end;
$self->_emit( exit => $self->{status} );
}
);
lib/AnyEvent/Proc.pm view on Meta::CPAN
sub fire_and_kill {
my $self = shift;
my $cb = ( ref $_[-1] eq 'CODE' ? pop : undef );
my $time = pop;
my $signal = uc( pop || 'TERM' );
my $w = AnyEvent->timer(
after => $time,
cb => sub {
return unless $self->alive;
$self->kill;
}
view all matches for this distribution
view release on metacpan or search on metacpan
lib/AnyEvent/Process.pm view on Meta::CPAN
package AnyEvent::Process::Job;
use strict;
sub new {
my ($ref, $pid) = @_;
my $self = bless {pid => $pid, cbs => [], handles => [], timers => []}, $ref;
return $self;
}
sub kill {
lib/AnyEvent/Process.pm view on Meta::CPAN
sub _add_handle {
my ($self, $handle) = @_;
push @{$self->{handles}}, $handle;
}
sub _add_timer {
my ($self, $timer) = @_;
push @{$self->{timers}}, $timer;
}
sub _remove_cbs {
undef $_[0]->{cbs};
}
sub _remove_timers {
my $self = shift;
undef $_ foreach @{$self->{timers}};
undef $self->{timers};
}
sub close {
my $self = shift;
undef $_ foreach @{$self->{handles}};
lib/AnyEvent/Process.pm view on Meta::CPAN
$job->_add_handle($hdl);
}
# Create callbacks
my $completion_cb = sub {
$job->_remove_timers();
AE::log info => "Process $job->{pid} finished with code $_[1].";
$set_on_completion_args->($job, $_[1]);
};
$job->_add_cb(AE::child $pid, $callback_factory->($completion_cb));
$self->{job} = $job;
# Create watchdog and kill timers
my $on_kill = $proc_args{on_kill} // sub { $_[0]->kill(9) };
if (defined $proc_args{kill_interval}) {
my $kill_cb = sub {
$job->_remove_timers();
AE::log warn => "Process $job->{pid} is running too long, killing it.";
$on_kill->($job);
};
$job->_add_timer(AE::timer $proc_args{kill_interval}, 0, $kill_cb);
}
if (defined $proc_args{watchdog_interval} or defined $proc_args{on_watchdog}) {
unless (defined $proc_args{watchdog_interval} &&
defined $proc_args{on_watchdog}) {
croak "Both or none of watchdog_interval and on_watchdog must be defined";
}
my $watchdog_cb = sub {
AE::log info => "Executing watchdog for process $job->{pid}.";
unless ($proc_args{on_watchdog}->($job)) {
$job->_remove_timers();
AE::log warn => "Watchdog for process $job->{pid} failed, killing it.";
$on_kill->($job);
}
};
$job->_add_timer(AE::timer $proc_args{watchdog_interval}, $proc_args{watchdog_interval}, $watchdog_cb);
}
}
# We need this to allow AE collecting pending signals and prevent accumulation of zombies
$self->_yield;
view all matches for this distribution
view release on metacpan or search on metacpan
lib/AnyEvent/Processor/Watcher.pm view on Meta::CPAN
sub start {
my $self = shift;
$self->action->start_message(),
$self->wait( AnyEvent->timer(
after => $self->delay,
interval => $self->delay,
cb => sub {
$self->action()->process_message(),
},
view all matches for this distribution
view release on metacpan or search on metacpan
t/10-block.t view on Meta::CPAN
}
my $p_in = AnyEvent::Promise->new(sub {
check_order(5);
my $cv = AnyEvent->condvar;
my $w; $w = AnyEvent->timer(
after => 1,
cb => sub {
check_order(6);
$cv->send('foobar');
undef $w;
t/10-block.t view on Meta::CPAN
});
my $p_out = AnyEvent::Promise->new(sub {
check_order(2);
my $cv = AnyEvent->condvar;
my $w; $w = AnyEvent->timer(
after => 1,
cb => sub {
check_order(3);
$cv->send($p_in);
undef $w;
view all matches for this distribution
view release on metacpan or search on metacpan
lib/AnyEvent/Promises/Deferred.pm view on Meta::CPAN
sub _promise_sync {
my $this = shift;
my $timeout = shift || 5;
my $cv = AE::cv;
my $tm = AE::timer $timeout, 0, sub { $cv->send("TIMEOUT\n") };
$this->_promise_then( sub { $cv->send( undef, @_ ); }, sub { $cv->send(@_) } );
my ( $error, @res ) = $cv->recv;
die $error if $error;
return wantarray? @res: $res[0];
lib/AnyEvent/Promises/Deferred.pm view on Meta::CPAN
&{ shift @POSTPONE } while @POSTPONE;
};
$postpone = sub {
push @POSTPONE, shift;
$POSTPONE_W ||= AE::timer( 0, 0, $postpone_exec );
();
};
};
sub _do_then {
view all matches for this distribution
view release on metacpan or search on metacpan
lib/AnyEvent/RFXCOM/RX.pm view on Meta::CPAN
sub cleanup {
my ($self, $error) = @_;
$self->SUPER::cleanup(@_);
undef $self->{discard_timer};
undef $self->{dup_timer};
}
sub anyevent_read_type {
my ($handle, $cb, $self) = @_;
view all matches for this distribution
view release on metacpan or search on metacpan
lib/AnyEvent/RTPG.pm view on Meta::CPAN
$self->event("refresh_status"=>\@$list);
}
sub start {
my $self = shift;
$self->{_tick_timer} = AE::timer(0, 10, sub { $self->_tick });
}
sub rpc_command {
my $self = shift;
my ($result, $error)=$self->{_rtpg}->rpc_command(@_);
view all matches for this distribution
view release on metacpan or search on metacpan
lib/AnyEvent/RabbitMQ/Fork.pm view on Meta::CPAN
sub drain_writes {
my ($self, $to) = @_;
my $w;
if ($to) {
$w = AE::timer $to, 0,
sub { $self->_drain_cv->croak("Timed out after $to") };
}
$self->_drain_cv->recv;
$self->_clear_drain_cv;
view all matches for this distribution
view release on metacpan or search on metacpan
example/simplest.pl view on Meta::CPAN
}
$loop->croak("[ERROR] $event($details): $why" );
},
);
# publisher timer
my $t;
# connect and set up channel
my $conn = $rmq->connect();
$conn->cb(
example/simplest.pl view on Meta::CPAN
print "************* consuming\n";
consume($channel, $queue_name);
print "************* starting publishing\n";
$t = AE::timer 0, 1.0, sub { publish($channel, $queue_name, "message prepared at ". scalar(localtime) ) };
}
);
# consumes from requested queue
sub consume {
view all matches for this distribution
view release on metacpan or search on metacpan
lib/AnyEvent/RabbitMQ.pm view on Meta::CPAN
$self->{_handle}->push_read(chunk => $length, sub {
my $self = $weak_self or return;
$stack .= $_[1];
my ($frame) = Net::AMQP->parse_raw_frames(\$stack);
$self->{_heartbeat_recv} = time if $self->{_heartbeat_timer};
if ($self->{verbose}) {
warn '[C] <-- [S] ', Dumper($frame),
'-----------', "\n";
}
lib/AnyEvent/RabbitMQ.pm view on Meta::CPAN
if ($self->{_state} == _ST_CLOSED) {
return $method_frame && $method_frame->isa('Net::AMQP::Protocol::Connection::CloseOk');
}
if ($method_frame && $method_frame->isa('Net::AMQP::Protocol::Connection::Close')) {
delete $self->{_heartbeat_timer};
$self->_push_write(Net::AMQP::Protocol::Connection::CloseOk->new());
$self->_server_closed($close_cb, $frame);
return;
}
lib/AnyEvent/RabbitMQ.pm view on Meta::CPAN
my $close_cb = $args{on_close};
my $failure_cb = $args{on_read_failure};
my $last_recv = 0;
my $idle_cycles = 0;
weaken(my $weak_self = $self);
my $timer_cb = sub {
my $self = $weak_self or return;
if ($self->{_heartbeat_recv} != $last_recv) {
$last_recv = $self->{_heartbeat_recv};
$idle_cycles = 0;
}
elsif (++$idle_cycles > 1) {
delete $self->{_heartbeat_timer};
$failure_cb->("Heartbeat lost");
$self->_server_closed($close_cb, "Heartbeat lost");
return;
}
$self->_push_write(Net::AMQP::Frame::Heartbeat->new());
};
$self->{_heartbeat_recv} = time;
$self->{_heartbeat_timer} = AnyEvent->timer(
after => $interval,
interval => $interval,
cb => $timer_cb,
);
return $self;
}
lib/AnyEvent/RabbitMQ.pm view on Meta::CPAN
sub drain_writes {
my ($self, $timeout) = shift;
$self->{drain_condvar} = AnyEvent->condvar;
if ($timeout) {
$self->{drain_timer} = AnyEvent->timer( after => $timeout, sub {
$self->{drain_condvar}->croak("Timed out after $timeout");
});
}
$self->{drain_condvar}->recv;
delete $self->{drain_timer};
}
sub DESTROY {
my $self = shift;
$self->close() unless in_global_destruction;
view all matches for this distribution
view release on metacpan or search on metacpan
# called for each line entered by the user
AnyEvent::ReadLine::Gnu->print ("you entered: $_[0]\n");
};
# asynchronously print something
my $t = AE::timer 1, 1, sub {
$rl->hide;
print "async message 1\n"; # mind the \n
$rl->show;
# the same, but shorter:
view all matches for this distribution
view release on metacpan or search on metacpan
lib/AnyEvent/Redis/Federated.pm view on Meta::CPAN
if ($self->{server_status}{"$server:retry_pending"}) {
warn "retry already pending for $server, skipping\n" if $self->{debug};
return 1;
}
# ok, schedule the timer to re-check. this should NOT be a
# recurring timer, otherwise we end up with a bunch of pending
# retries since the "interval" is likely shorter than TCP timeout.
# eventually this will error out, in which case we'll try it again
# by calling markServerDown() after clearying retry_pending, or
# it'll work and we're good to go.
my $t;
my $r;
$t = AnyEvent->timer(
after => $delay,
cb => sub {
warn "timer callback triggered for $server" if $self->{debug};
my ($host, $port) = split /:/, $server;
print "attempting reconnect to $server\n" if $self->{debug};
$r = AnyEvent::Redis->new(
host => $host,
port => $port,
lib/AnyEvent/Redis/Federated.pm view on Meta::CPAN
warn "retry ping got $val instead of PONG" if $self->{debug};
}
$self->{conn}->{$server} = $r;
$self->{server_status}{"$server:retry_pending"} = 0;
$self->markServerUp($server);
undef $t; # we need to keep a ref to the timer here so it runs at all
});
}
);
warn "scheduled health check of $server in $delay secs\n" if $self->{debug};
$self->{server_status}{"$server:retry_pending"} = 1;
lib/AnyEvent/Redis/Federated.pm view on Meta::CPAN
$self->{cv}->end;
undef $w;
}
}
});
print "scheduling alarm timer in poll() for $timeout\n" if $self->{debug};
alarm($timeout);
}
$self->{cv}->recv;
$self->{cv} = undef;
view all matches for this distribution
view release on metacpan or search on metacpan
examples/subs.pl view on Meta::CPAN
}
},
}
);
my $timer;
$timer = AE::timer( 5, 0,
sub {
undef( $timer );
exit 0; # Emergency exit
},
);
};
view all matches for this distribution
view release on metacpan or search on metacpan
lib/AnyEvent/Retry.pm view on Meta::CPAN
is => 'ro',
isa => 'Bool',
default => 0,
);
has '_timer' => (
init_arg => undef,
writer => '_set_timer',
clearer => 'kill_timer',
predicate => 'has_timer',
);
sub BUILD {
my $self = shift;
$self->start if $self->autostart;
}
sub DEMOLISH {
my $self = shift;
$self->kill_timer;
if(!$self->_sent_result){
$self->_sent_result(1);
$self->on_failure->(demolish => 'DEMOLISH');
}
}
# set a timer to call handle_tick in the future
sub set_timer {
my ($self, $time, $i) = @_;
return $self->handle_tick($i) if $time <= 0;
weaken $self;
$self->_set_timer(
AnyEvent->timer( after => $time, cb => sub {
$self->kill_timer;
$self->handle_tick($i);
}),
);
return;
}
# called when the timer ticks; start the user's code running
sub handle_tick {
my ($self, $this_i) = @_;
$self->run_code;
}
lib/AnyEvent/Retry.pm view on Meta::CPAN
$self->on_failure->( max_tries => $self->max_tries );
return;
}
# we didn't get the result this time, and we haven't exceeded
# $max_tries, so set the timer and do the whole thing again
$self->set_timer( $next_time, $next_i );
return;
}
# start the user's code running, with a continuation-passing-style
# callback to call when the result is ready
lib/AnyEvent/Retry.pm view on Meta::CPAN
try { $self->try->($success, $error) }
catch { $self->handle_result(0, 'startup error', $_) };
return;
}
# if the timer is running, stop it until resume is called
sub pause {
my $self = shift;
$self->kill_timer;
}
# fake a timer tick; run the user code, and set the timer to retry if
# necessary
sub resume {
my $self = shift;
$self->kill_timer; # just in case
$self->handle_tick(0);
}
# start the process. if the timer is running, die. if the timer is
# not running, start completely over.
sub start {
my $self = shift;
confess 'the job is already running' if $self->has_timer;
$self->interval->reset;
$self->_sent_result(0);
$self->set_timer( $self->after, 0 );
return;
}
__PACKAGE__->meta->make_immutable;
lib/AnyEvent/Retry.pm view on Meta::CPAN
(You can call this again when the job is done to run the job again.)
=head2 pause
Stop the timer, pausing the job until C<resume> is called.
=head2 resume
Resume the task as though the last-running timer just expired.
=head1 INITARGS
=head2 try
view all matches for this distribution
view release on metacpan or search on metacpan
lib/AnyEvent/RetryTimer.pm view on Meta::CPAN
our $VERSION = '0.1';
=head1 NAME
AnyEvent::RetryTimer - Retry timers for AnyEvent
=head1 VERSION
0.1
lib/AnyEvent/RetryTimer.pm view on Meta::CPAN
use AnyEvent::RetryTimer;
my $con =
Something::Connection->new;
my $timer;
$con->on_disconnect (sub {
$timer ||=
AnyEvent::RetryTimer->new (
on_retry => sub {
$con->connect;
});
$timer->retry;
my $secs = $timer->current_interval;
warn "Lost connection, reconnecting in $secs seconds!";
});
$con->on_connect (sub {
warn "Connected successfully!";
$timer->success;
undef $timer;
});
=head1 DESCRIPTION
This is a small helper utility to manage timed retries.
This is a pattern I often stumble across when managing network connections.
And I'm tired to reimplement it again and again. So I wrote this module.
At the moment it only implements a simple exponential back off retry mechanism
(with configurable multiplier) using L<AnyEvent> timers. If there are
other back off strategies you find useful you are free to send a
feature request or even better a patch!
=head1 METHODS
=over 4
=item my $timer = AnyEvent::RetryTimer->new (%args)
This is the constructor, it constructs the object.
At the end of the objects lifetime, when you get rid of the last reference to
C<$timer>, it will stop and running timeouts and not call any of the configured
callbacks again.
C<%args> can contain these keys:
=over 4
=item on_retry => $retry_cb->($timer)
C<$retry_cb> is the callback that will be called for (re)tries.
When this constructor is called and no C<no_first_try> is given,
an initial retry interval of the length 0 is started, which counts as the
first try.
Later it is also called after a retry interval has passed, which was initiated
by a call to the C<retry> method.
The first argument is the C<$timer> object itself.
=item no_first_try => $bool
This parameter defines whether the C<$retry_cb> will be called when the
L<AnyEvent::RetryTimer> object is created or not. If C<$bool> is true
lib/AnyEvent/RetryTimer.pm view on Meta::CPAN
Please note that a call to C<success> will of course reset the internal count
of calls to C<retry>.
Default for this option is C<0> (disabled).
=item on_max_retries => $max_retry_cb->($timer)
After C<max_retries> the C<$max_retry_cb> callback will be
called with the C<$timer> as first argument.
It is usually called when a call to C<retry> would exceed
C<max_retries>.
=back
lib/AnyEvent/RetryTimer.pm view on Meta::CPAN
my $rself = $self;
weaken $self;
$self->{timer} = AE::timer 0, 0, sub {
delete $self->{timer};
$self->{on_retry}->($self) if $self;
};
return $rself
}
=item $timer->retry
This method initiates or continues retries. If already a retry interval
is installed (eg. by the constructor or another previous unfinished call
to C<retry>), the call will be a nop.
lib/AnyEvent/RetryTimer.pm view on Meta::CPAN
sub retry {
my ($self) = @_;
weaken $self;
return if $self->{timer};
if ($self->{backoff} eq 'exponential') {
my $r;
# layout of $r = [$interval, $retry_cnt]
lib/AnyEvent/RetryTimer.pm view on Meta::CPAN
} else {
$r = $self->{r} = [$self->{start_interval}];
}
$self->{timer} = AE::timer $r->[0], 0, sub {
$r->[1]++;
delete $self->{timer};
$self->{on_retry}->($self)
if $self && $self->{on_retry};
};
}
}
=item $timer->success
This signals that the last retry was successful and it will
reset any state or intervals to the initial settings given
to the constructor.
You can reuse the C<$timer> object after a call to C<success>.
=cut
sub success {
my ($self) = @_;
delete $self->{r}; # reset timer & wait counter
delete $self->{timer};
}
=item my $secs = $timer->current_interval
Returns the length of the current interval to the
next call to the C<$retry_cb>.
=cut
sub current_interval {
my ($self) = @_;
# specialcase: first call
return 0 if $self->{timer} && not $self->{r};
if ($self->{backoff} eq 'exponential') {
return unless $self->{r};
return $self->{r}->[0];
}
view all matches for this distribution
view release on metacpan or search on metacpan
examples/example.pl view on Meta::CPAN
warn "$host:$port: " . $err->message . "\n";
},
);
my $cv = AE::cv;
my $timer;
$cluster->get( '__last__',
sub {
my $num = shift || 0;
my $err = shift;
examples/example.pl view on Meta::CPAN
$cv->send;
return;
}
$timer = AE::timer( 0, 0.1,
sub {
set_get( $num++ );
}
);
}
view all matches for this distribution
view release on metacpan or search on metacpan
examples/subs.pl view on Meta::CPAN
$cv->send;
}
);
my $timer;
$timer = AE::timer( 5, 0,
sub {
undef( $timer );
exit 0; # Emergency exit
},
);
};
view all matches for this distribution
view release on metacpan or search on metacpan
$cv->send;
},
);
# Timeout in case of error
my $w = AnyEvent->timer( after => 2, cb => sub {
fail("$testname timed out");
$cv->send;
} );
if ( $stdin ) {
view all matches for this distribution
view release on metacpan or search on metacpan
use AnyEvent::Handle;
use AnyEvent::Util;
use AnyEvent::SCGI;
my $ticker = AE::timer 1,1,sub { diag "tick\n" };
my $z = "\0"; # to prevent interpolation
run_test(
"CONTENT_LENGTH${z}27${z}SCGI${z}1${z}". # headers
"REQUEST_METHOD${z}POST${z}".
view all matches for this distribution
view release on metacpan or search on metacpan
lib/AnyEvent/SIP.pm view on Meta::CPAN
L<Net::SIP> requires dispatchers (event loops) to check their stopvars
(condition variables) every single iteration of the loop. In my opinion, it's
a wasteful and heavy operation. When it comes to loops like L<EV>, they run
a B<lot> of cycles, and it's not very effecient and causes heavy load.
To avoid that, the default mode for L<AnyEvent::SIP> is to set up a timer
to check the condition variables. Default interval is: B<0.2> seconds.
To configure this, you can set up the interval on import:
use AnyEvent::SIP stopvar_interval => 0.1;
view all matches for this distribution
view release on metacpan or search on metacpan
t/30-server-func.t view on Meta::CPAN
});
$conn = sub {
$cg = tcp_connect '127.0.0.1',$port, sub {
return $cv->end if @_;
$!{ENODATA} or $!{ECONNREFUSED} or plan skip_all => "Bad response from server connect: [".(0+$!)."] $!";
my $t;$t = AnyEvent->timer( after => 0.05, cb => sub { undef $t; $conn->() } );
};
};
$conn->();
$cv->recv;
}
view all matches for this distribution
view release on metacpan or search on metacpan
$MESSAGE_PROCESSING->msg_handle_delete ($pdu->msg_id)
if $pdu->expect_response;
# A crude attempt to recover from temporary failures.
if ($retries-- > 0 && ($!{EAGAIN} || $!{EWOULDBLOCK} || $!{ENOSPC})) {
my $retry_w; $retry_w = AE::timer $pdu->timeout, 0, sub {
undef $retry_w;
_send_pdu ($pdu, $retries);
};
} else {
--$BUSY;
$MAX_OUTSTANDING = (int $MAX_OUTSTANDING * 0.95) || 1;
};
}
$msg->timeout_id (\(my $rtimeout_w =
AE::timer $pdu->timeout, 0, sub {
my $rtimeout_w = $msg->timeout_id;
if ($$rtimeout_w) {
undef $$rtimeout_w;
delete $TRANSPORT[$fileno]
unless --$TRANSPORT[$fileno][0];
# $delay is not very sensibly implemented by AnyEvent::SNMP,
# but apparently it is not a very sensible feature.
if ($delay > 0) {
++$BUSY;
my $delay_w; $delay_w = AE::timer $delay, 0, sub {
undef $delay_w;
push @QUEUE, $pdu;
--$BUSY;
kick_job;
};
view all matches for this distribution
view release on metacpan or search on metacpan
examples/connection_handling.pl view on Meta::CPAN
use AnyEvent::STOMP::Client;
my $stomp_client = new AnyEvent::STOMP::Client();
my $backoff = 0;
my $backoff_timer;
sub backoff {
$backoff_timer = AnyEvent->timer(
after => $backoff,
cb => sub { $stomp_client->connect(); }
);
}
view all matches for this distribution
view release on metacpan or search on metacpan
lib/AnyEvent/SlackBot.pm view on Meta::CPAN
SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE,
SSL_hostname => '',
verify_hostname => 0
);
my $response=$ua->request($request);
$self->{timer}=undef;
if($response->code==200) {
my $data=eval { from_json($response->decoded_content) };
if($@) {
return $self->new_false("Failed to decode response, error was: $@");
}
lib/AnyEvent/SlackBot.pm view on Meta::CPAN
return $self->handle_reconnect;
}
$self->stats->{last_connected_on}=time;
$self->stats->{total_connections}++;
$self->stats->{last_msg_on}=time;
$self->{timer}=AnyEvent->timer(
interval=>$self->keep_alive_timeout,
after=>$self->keep_alive_timeout,
cb=>sub {
my $max_timeout=$self->stats->{last_msg_on} + 3 * $self->keep_alive_timeout;
if(time < $max_timeout) {
lib/AnyEvent/SlackBot.pm view on Meta::CPAN
while(my $msg=shift @{$self->{backlog}}) {
$self->send($msg);
}
} else {
$self->log_error("Failed to reconnect will try again in 15 seconds, error was: $result");
$self->{timer}=AnyEvent->timer(
interval=>$self->keep_alive_timeout,
after=>$self->keep_alive_timeout,
cb=>sub { $self->handle_reconnect },
);
}
view all matches for this distribution
view release on metacpan or search on metacpan
lib/AnyEvent/SlackRTM.pm view on Meta::CPAN
$conn->on( each_message => sub { $self->_handle_incoming(@_) } );
$conn->on( finish => sub { $self->_handle_finish(@_) } );
my $started = localtime;
$self->{_last_keep_alive} = time;
$self->{keep_alive} = AnyEvent->timer(
after => 15,
interval => 15,
cb => sub {
my $id = $self->{id};
my $now = time;
lib/AnyEvent/SlackRTM.pm view on Meta::CPAN
my $keep_alive;
my $counter;
$rtm->on('hello' => sub {
print "Ready\n";
$keep_alive = AnyEvent->timer(interval => 60, cb => sub {
print "Ping\n";
$rtm->ping;
});
$counter = AnyEvent->timer(interval => 5, cb => sub {
print "Send\n";
$rtm->send({
type => 'message',
channel => $channel_id,
text => "".$i++,
lib/AnyEvent/SlackRTM.pm view on Meta::CPAN
This will establish the WebSocket connection to the Slack RTM service.
You should have registered any events using L</on> before doing this or you may miss some events that arrive immediately.
Sets up a "keep alive" timer,
which triggers every 15 seconds to send a C<ping> message
if there hasn't been any activity in the past 10 seconds.
The C<ping> will trigger a C<pong> response,
so there should be at least one message every 15 seconds.
This will disconnect if no messages have been received in the past 30 seconds;
view all matches for this distribution
view release on metacpan or search on metacpan
lib/AnyEvent/HTTP/Spark.pm view on Meta::CPAN
# sets the web service the requests point to
retryCount: 1, how many retries to attempt when getting a 429 error
Options set at runtime
retries: anymous hash, used to trak AnyEvent->timer objects
=cut
# This method runs after the new constructor
sub BUILD {
lib/AnyEvent/HTTP/Spark.pm view on Meta::CPAN
my $timeout=looks_like_number($response->header('Retry-After')) ? $response->header('Retry-After') : $self->retryTimeout;
$self->log_warn("Request: $id recived a 429 response, will retry in $timeout seconds");
if($count>0) {
my $ae;
$ae=AnyEvent->timer(after=>$timeout,cb=>sub {
my $next_id=$self->queue_request($request,sub {
my ($self,undef,$result,undef,$response)=@_;
$wrap->($self,$id,$result,$request,$response);
});
$self->add_ids_for_blocking($next_id);
lib/AnyEvent/HTTP/Spark.pm view on Meta::CPAN
my ($self,undef,$result,undef,$response)=@_;
$cb->($self,$id,$result,$request,$response);
};
my $ae;
$ae=AnyEvent->timer(after=>$timeout,cb=>sub {
my $next_id=$self->queue_request($request,$code);
$self->add_ids_for_blocking($next_id);
$self->agent->run_next;
delete $self->retries->{$ae};
undef $ae;
view all matches for this distribution