Result:
found more than 725 distributions - search limited to the first 2001 files matching your query ( run in 1.111 )


AnyEvent-Handle-Throttle

 view release on metacpan or  search on metacpan

lib/AnyEvent/Handle/Throttle.pm  view on Meta::CPAN

        $global_upload_speed   = $global__upload_speed;
        $global_download_speed = $global__download_speed;
        $global__upload_speed  = $global__download_speed = 0;
    };
    $global_reset_cb->();
    our $global_reset = AE::timer(0, $global_period, $global_reset_cb);

    sub _start {
        my $self  = shift;
        my $reset = sub {
            $self->{read_size}      = $self->{download_limit};

lib/AnyEvent/Handle/Throttle.pm  view on Meta::CPAN

            $self->{upload_speed}   = $self->{_upload_speed};
            $self->{download_speed} = $self->{_download_speed};
            $self->{_upload_speed}  = $self->{_download_speed} = 0;
        };
        $self->{_period} ||= 1;
        $self->{_reset} = AE::timer(0, $self->{_period}, $reset);
        $reset->();
        $self->SUPER::_start(@_);
    }

    sub start_read {

lib/AnyEvent/Handle/Throttle.pm  view on Meta::CPAN

                    $self->{read_size};
                my ($period) = sort grep {defined} $global_period,
                    $self->{_period};
                if (defined $read && $read <= 0) {
                    $self->stop_read;
                    return $self->{_pause_read} = AE::timer(
                        $period, 0,
                        sub {
                            delete $self->{_pause_read};
                            $self->start_read;
                        }

lib/AnyEvent/Handle/Throttle.pm  view on Meta::CPAN

                my ($period) = sort grep {defined} $global_period,
                    $self->{_period};
                if (defined $write && $write <= 0) {
                    if (length $self->{wbuf}) {
                        delete $self->{_ww};
                        return $self->{_pause_ww} = AE::timer(
                            0.5, 0,
                            sub {
                                delete $self->{_pause_write};
                                $poll->();
                            }

 view all matches for this distribution


AnyEvent-Handle-UDP

 view release on metacpan or  search on metacpan

lib/AnyEvent/Handle/UDP.pm  view on Meta::CPAN


for my $dir ('', 'r', 'w') {
	my $timeout = "${dir}timeout";
	my $activity = "${dir}activity";
	my $on_timeout = "on_$timeout";
	my $timer = "${dir}timer";
	my $clear_timeout = "clear_$timeout";
	my $timeout_reset = "${timeout}_reset";

	my $callback;
	$callback = sub {
		my $self = shift;
		if (not exists $self->{$timeout} or not $self->{fh}) {
			delete $self->{$timer};
			return;
		}
		my $now = AE::now;
		my $after = $self->{$activity} + $self->{$timeout} - $now;
		if ($after <= 0) {

lib/AnyEvent/Handle/UDP.pm  view on Meta::CPAN

			$time ? $time->($self) : $self->_error(0, $error);
			return if not exists $self->{$timeout};
		}
		Scalar::Util::weaken($self);
		return if not $self;
		$self->{$timer} = AE::timer($after, 0, sub {
			delete $self->{$timer};
			$callback->($self);
		});
	};

	_insert($timeout, sub {
		my $self = shift;
		if (@_) {
			my $value = shift;
			$self->{$timeout} = $value;
			if ($value == 0) {
				delete $self->{$timer};
				delete $self->{$timeout};
				return;
			}
			else {
				$callback->($self);

 view all matches for this distribution


AnyEvent-Hiredis

 view release on metacpan or  search on metacpan

bin/bench.pl  view on Meta::CPAN

    $i--;
    $redis->command(['SET', $key.$i, $value], $i < 0 ? $done : $set);
};
$set->() for 1..100;

my $timer = AnyEvent->timer( after => 3, interval => 3, cb => sub {
    say "$i items remaining";
});

my $start = AnyEvent->now;
$done->recv;

 view all matches for this distribution


AnyEvent-I3

 view release on metacpan or  search on metacpan

lib/AnyEvent/I3.pm  view on Meta::CPAN


    my $cv = AnyEvent->condvar;

    my $version_cv = $self->message(TYPE_GET_VERSION);
    my $timeout;
    $timeout = AnyEvent->timer(
        after => 1,
        cb => sub {
            warn "Falling back to i3 --version since the running i3 doesn’t support GET_VERSION yet.";
            my $version = _call_i3('--version');
            $version =~ s/^i3 version //;

 view all matches for this distribution


AnyEvent-IMAP

 view release on metacpan or  search on metacpan

example/demo.pl  view on Meta::CPAN

unless ($ok) {
    die $res;
}

# send ping
my $timer = AE::timer(30, 20*60, sub {
    $imap->noop();
});

AE::cv()->recv;

 view all matches for this distribution


AnyEvent-IRC

 view release on metacpan or  search on metacpan

lib/AnyEvent/IRC.pm  view on Meta::CPAN

   use AnyEvent;
   use AnyEvent::IRC::Client;

   my $c = AnyEvent->condvar;

   my $timer;
   my $con = new AnyEvent::IRC::Client;

   $con->reg_cb (registered => sub { print "I'm in!\n"; });
   $con->reg_cb (disconnect => sub { print "I'm out!\n"; $c->broadcast });
   $con->reg_cb (

lib/AnyEvent/IRC.pm  view on Meta::CPAN

         my ($con) = @_;

         if ($_[2] eq 'PRIVMSG') {
            print "Sent message!\n";

            $timer = AnyEvent->timer (
               after => 1,
               cb => sub {
                  undef $timer;
                  $con->disconnect ('done')
               }
            );
         }
      }

 view all matches for this distribution


AnyEvent-Ident

 view release on metacpan or  search on metacpan

t/alt_res_class.t  view on Meta::CPAN

use warnings;
use Test::More tests => 7;
use AnyEvent::Ident::Client;
use AnyEvent::Ident::Server;

our $timeout = AnyEvent->timer( 
  after => 10,
  cb    => sub { diag "TIMEOUT"; exit },
);

my $bindport = AnyEvent->condvar;

t/alt_res_class.t  view on Meta::CPAN

};
diag $@ if $@;

like $bindport->recv, qr/^[1-9]\d*$/, 'bind port = ' . $server->bindport;

my $w = AnyEvent->timer( after => 5, cb => sub { diag 'TIMEOUT'; exit });

my $done = AnyEvent->condvar;

my $client = AnyEvent::Ident::Client->new(
  hostname => '127.0.0.1',

 view all matches for this distribution


AnyEvent-Impl-NSRunLoop

 view release on metacpan or  search on metacpan

lib/AnyEvent/Impl/NSRunLoop.pm  view on Meta::CPAN

sub io {
    my ($class, %arg) = @_;
    Cocoa::EventLoop->io(%arg);
}

sub timer {
    my ($class, %arg) = @_;
    Cocoa::EventLoop->timer(%arg);
}

sub loop {
    Cocoa::EventLoop->run;
}

 view all matches for this distribution


AnyEvent-Impl-Prima

 view release on metacpan or  search on metacpan

lib/AnyEvent/Impl/Prima.pm  view on Meta::CPAN

  use Prima;
  use AnyEvent::Impl::Prima;
  
  my $mw = Prima::MainWindow->new();
  
  my $timer = AnyEvent->timer(
      after => 10,
      cb => sub { $mw->close; },
  );

  Prima->run;

lib/AnyEvent/Impl/Prima.pm  view on Meta::CPAN

    $f
} 

sub AnyEvent::Impl::Prima::Timer::DESTROY { ${$_[0]}->destroy if $_[0] and ${$_[0]} }

sub timer { my ( $s, %r ) = @_;
    my($c,$g) = $r{cb};
    
    my $next = $r{ after } || $r{ interval };
    my $repeat = delete $r{ interval };

    
    # Convert to miliseconds for Prima
    $next *= 1000;
    $repeat *= 1000 if $repeat;
    
    my %timer_params = (
        timeout => $next,
    );
    my $timer = Prima::Timer->new(
        timeout => $next,
        onTick  => sub {
            #warn "Timer $_[0] fired";
            if( $repeat ) {
                $_[0]->timeout( $repeat );

lib/AnyEvent/Impl/Prima.pm  view on Meta::CPAN

        onDestroy => sub { my ( $self ) = @_;
            #warn "Discarding $self";
            $self->stop;
        },
    );
    #warn "Starting new timer $res";
    $timer->start;
    return bless \ $timer, "AnyEvent::Impl::Prima::Timer";
}

sub poll {
    require Prima::Application;
    $::application->yield;

 view all matches for this distribution


AnyEvent-InMemoryCache

 view release on metacpan or  search on metacpan

lib/AnyEvent/InMemoryCache.pm  view on Meta::CPAN

    } else {
        $expires_in = parse_duration($expires_in);
    }
    $self->{_datastore}{$key} = [
        $val,
        ($expires_in < 0 ? undef : AE::timer $expires_in, 0, sub{ delete $self->{_datastore}{$key} })
    ];
    $val;
}

sub get {

lib/AnyEvent/InMemoryCache.pm  view on Meta::CPAN

    $cache->set(immortal => "Don't expire!");  # It lasts forever by default
    say $cache->get("immortal");  # "Don't expire!"
    
    $cache->set(a_second => "Expire soon", "1s");  # Expires in one-second.
    say $cache->get('a_second');  # "Expires soon"
    AE::timer 2, 0, sub{  # 2 seconds later
        $cache->exists('a_second');  # false
    };
    
    # You can overwrite key, and it's mortal now.
    $cache->set(immortal => 'will die...', "10min");

 view all matches for this distribution


AnyEvent-JSONRPC-Lite

 view release on metacpan or  search on metacpan

t/disconnect.t  view on Meta::CPAN

            $state = 'disconnected';
        },
        on_read => sub {  },
    );
}, sub {
    my $t; $t = AnyEvent->timer(
        after => 1,
        cb    => sub {
            $ready->send;
            undef $t;
        },

t/disconnect.t  view on Meta::CPAN

{
    my $client = jsonrpc_client '127.0.0.1', $port;
    # disconnect soon after leaving this scope

    my $sleep = AnyEvent->condvar;
    my $t; $t = AnyEvent->timer( after => 1, cb => sub { $sleep->send });
    $sleep->recv;
}

my $cv = AnyEvent->condvar;

my ($client, $timer1, $timer2);
my $t = AnyEvent->timer(
    after => 1,
    cb    => sub {
        is $state, 'disconnected', 'already disconnected ok';

        $client = jsonrpc_client '127.0.0.1', $port;
        $timer1 = AnyEvent->timer(
            after => 0.5,
            cb    => sub {
                is $state, 'connected', 'connected at this time ok';
                undef $client;  # disconnect here
            },
        );

        $timer2 = AnyEvent->timer(
            after => 1,
            cb    => sub {
                is $state, 'disconnected', 'connection disconnected ok';
                $cv->send;
            },

 view all matches for this distribution


AnyEvent-JSONRPC

 view release on metacpan or  search on metacpan

t/disconnect.t  view on Meta::CPAN

    # disconnect soon after leaving this scope
}

my $cv = AnyEvent->condvar;

my ($client, $timer1, $timer2);
my $t = AnyEvent->timer(
    after => 1,
    cb    => sub {
        is $state, 'disconnected', 'already disconnected ok';

        $client = jsonrpc_client '127.0.0.1', $port;
        $timer1 = AnyEvent->timer(
            after => 0.5,
            cb    => sub {
                is $state, 'connected', 'connected at this time ok';
                undef $client;  # disconnect here
            },
        );

        $timer2 = AnyEvent->timer(
            after => 1,
            cb    => sub {
                is $state, 'disconnected', 'connection disconnected ok';
                $cv->send;
            },

 view all matches for this distribution


AnyEvent-Lingr

 view release on metacpan or  search on metacpan

lib/AnyEvent/Lingr.pm  view on Meta::CPAN

    $lingr->on_error(sub {
        my ($msg) = @_;
        warn 'Lingr error: ', $msg;
    
        # reconnect after 5 seconds,
        my $t; $t = AnyEvent->timer(
            after => 5,
            cb    => sub {
                $lingr->start_session;
                undef $t;
            },

lib/AnyEvent/Lingr.pm  view on Meta::CPAN

    $lingr->on_error(sub {
        my ($msg) = @_;
        warn 'Lingr error: ', $msg;
    
        # reconnect after 5 seconds,
        my $t; $t = AnyEvent->timer(
            after => 5,
            cb    => sub {
                $lingr->start_session;
                undef $t;
            },

 view all matches for this distribution


AnyEvent-MP

 view release on metacpan or  search on metacpan

MP.pm  view on Meta::CPAN


   # temporarily execute code in port context
   peval $port, sub { die "kill the port!" };

   # execute callbacks in $SELF port context
   my $timer = AE::timer 1, 0, psub {
      die "kill the port, delayed";
   };

   # distributed database - modification
   db_set $family => $subkey [=> $value]  # add a subkey

MP.pm  view on Meta::CPAN


This is useful when you register callbacks from C<rcv> callbacks:

   rcv delayed_reply => sub {
      my ($delay, @reply) = @_;
      my $timer = AE::timer $delay, 0, psub {
         snd @reply, $SELF;
      };
   };

=cut

MP.pm  view on Meta::CPAN

Monitors the given C<$port> and keeps the passed references. When the port
is killed, the references will be freed.

Optionally returns a guard that will stop the monitoring.

This function is useful when you create e.g. timers or other watchers and
want to free them when the port gets killed (note the use of C<psub>):

  $port->rcv (start => sub {
     my $timer; $timer = mon_guard $port, AE::timer 1, 1, psub {
        undef $timer if 0.9 < rand;
     });
  });

=cut

MP.pm  view on Meta::CPAN

=cut

sub after($@) {
   my ($timeout, @action) = @_;

   my $t; $t = AE::timer $timeout, 0, sub {
      undef $t;
      ref $action[0]
         ? $action[0]()
         : snd @action;
   };

MP.pm  view on Meta::CPAN

      kil $SELF;
      &$cb;
   };

   if (defined $timeout) {
      $timeout = AE::timer $timeout, 0, sub {
         undef $timeout;
         kil $port;
         $cb->();
      };
   } else {

 view all matches for this distribution


AnyEvent-MPV

 view release on metacpan or  search on metacpan

MPV.pm  view on Meta::CPAN


   my $mpv = AnyEvent::MPV->new (trace => 1);

   $mpv->start ("--", $videofile);

   my $timer = AE::timer 2, 0, my $quit = AE::cv;
   $quit->recv;

This starts F<mpv> with the two arguments C<--> and C<$videofile>, which
it should load and play. It then waits two seconds by starting a timer and
quits. The C<trace> argument to the constructor makes F<mpv> more verbose
and also prints the commands and responses, so you can have an idea what
is going on.

In my case, the above example would output something like this:

MPV.pm  view on Meta::CPAN


   $mpv->start;
   $mpv->cmd_recv (loadfile => $mpv->escape_binary ($videofile));
   $mpv->cmd ("set", "pause", "no");

   my $timer = AE::timer 2, 0, my $quit = AE::cv;
   $quit->recv;

This specifies extra arguments in the constructor - these arguments are
used every time you C<< ->start >> F<mpv>, while the arguments to C<<
->start >> are only used for this specific clal to0 C<start>. The argument

MPV.pm  view on Meta::CPAN


               if (defined $skip) {
                  if ($skip) {
                     # delay a bit, in case we get two metadata changes in quick succession, e.g.
                     # because we have a skip at file load time.
                     $skip_delay = AE::timer 2/50, 0, sub {
                        $mpv->cmd ("no-osd", "add", "chapter", 1);
                        $mpv->cmd ("show-text", "skipped sponsorblock section \"$section\"", 3000);
                     };
                  } else {
                     undef $skip_delay;

 view all matches for this distribution


AnyEvent-MQTT

 view release on metacpan or  search on metacpan

lib/AnyEvent/MQTT.pm  view on Meta::CPAN

           socket => undef,
           host => '127.0.0.1',
           port => '1883',
           timeout => 30,
           wait => 'nothing',
           keep_alive_timer => 120,
           qos => MQTT_QOS_AT_MOST_ONCE,
           message_id => 1,
           user_name => undef,
           password => undef,
           tls => undef,

lib/AnyEvent/MQTT.pm  view on Meta::CPAN

                     {
                      expect => $expect,
                      message => $args,
                      cv => $cv,
                      timeout =>
                        AnyEvent->timer(after => $self->{keep_alive_timer},
                                        cb => subname 'ack_timeout_for_'.$mid =>
                                        sub {
                          print ref $self, " timeout waiting for ",
                            message_type_string($expect), "\n" if DEBUG;
                          delete $self->{inflight}->{$mid};

lib/AnyEvent/MQTT.pm  view on Meta::CPAN

    ($msg, $cv) = @_;
  } else {
    my $args = shift @{$self->{write_queue}} or return;
    ($msg, $cv) = @$args;
  }
  $self->_reset_keep_alive_timer();
  print STDERR "Sending: ", $msg->string, "\n" if DEBUG;
  $self->{message_log_callback}->('>', $msg) if ($self->{message_log_callback});
  $self->{_waiting} = [$msg, $cv];
  print '  ', (unpack 'H*', $msg->bytes), "\n" if DEBUG;
  $self->{handle}->push_write($msg->bytes);
  $cv;
}

sub _reset_keep_alive_timer {
  my ($self, $wait) = @_;
  undef $self->{_keep_alive_handle};
  my $method = $wait ? '_keep_alive_timeout' : '_send_keep_alive';
  $self->{_keep_alive_waiting} = $wait;
  my $weak_self = $self;
  weaken $weak_self;
  $self->{_keep_alive_handle} =
    AnyEvent->timer(after => $self->{keep_alive_timer},
                    cb => subname((substr $method, 1).'_cb' =>
                                  sub { $weak_self->$method(@_) }));
}

sub _send_keep_alive {
  my $self = shift;
  print STDERR "Sending: keep alive\n" if DEBUG;
  $self->_send(message_type => MQTT_PINGREQ);
  $self->_reset_keep_alive_timer(1);
}

sub _keep_alive_timeout {
  my $self = shift;
  print STDERR "keep alive timeout\n" if DEBUG;

lib/AnyEvent/MQTT.pm  view on Meta::CPAN


sub _keep_alive_received {
  my $self = shift;
  print STDERR "keep alive received\n" if DEBUG;
  return unless (defined $self->{_keep_alive_waiting});
  $self->_reset_keep_alive_timer();
}


sub connect {
  my ($self, $msg, $cv) = @_;

lib/AnyEvent/MQTT.pm  view on Meta::CPAN

                            # call user-defined on_connect function.
                            $weak_self->{on_connect}->($handle, $retry) if $weak_self->{on_connect};
                            my $msg =
                              Net::MQTT::Message->new(
                                message_type => MQTT_CONNECT,
                                keep_alive_timer => $weak_self->{keep_alive_timer},
                                client_id => $weak_self->{client_id},
                                clean_session => $weak_self->{clean_session},
                                will_topic => $weak_self->{will_topic},
                                will_qos => $weak_self->{will_qos},
                                will_retain => $weak_self->{will_retain},

lib/AnyEvent/MQTT.pm  view on Meta::CPAN


=item C<timeout>

The timeout for responses from the server.

=item C<keep_alive_timer>

The keep alive timer.

=item C<user_name>

The user name for the MQTT broker.

 view all matches for this distribution


AnyEvent-MSN

 view release on metacpan or  search on metacpan

examples/client.pl  view on Meta::CPAN

$AnyEvent::MSN::DEBUG++;
my ($user, $pass) = @ARGV;    # XXX - Better to use a GetOpt-like module
my $cv = AnyEvent->condvar;
($user, $pass) = ('anyevent_msn@hotmail.com', 'public');
($user, $pass) = ('msn@penilecolada.com',     'password');
my $reconnect_timer;

#
my $msn = AnyEvent::MSN->new(
    passport => $user,  # XXX - I may change the name of this arg before pause
    password => $pass,

examples/client.pl  view on Meta::CPAN

        warn 'Error: ' . $msg;
    },
    on_fatal_error => sub {
        my ($msn, $msg, $fatal) = @_;
        warn sprintf 'Fatal error: ' . $msg;
        $reconnect_timer = AE::timer 30, 0, sub {
            return $msn->connect if $msn->connected;
            $cv->send;
            }
    }
);

 view all matches for this distribution


AnyEvent-Mac-Pasteboard

 view release on metacpan or  search on metacpan

lib/AnyEvent/Mac/Pasteboard.pm  view on Meta::CPAN

            $on_unchange->($self->pbpaste());
        }
    };

    if ( @interval == 1 ) {
        $self->{timer} = AE::timer 0, $interval[0], $on_time_core;
    }
    else {
        my $on_time; $on_time = sub {
            $on_time_core->();
            my $wait_sec = $interval_idx < @interval ? $interval[$interval_idx++] : $interval[-1];
            $self->{timer} = AE::timer $wait_sec, 0, $on_time;
        };

        ### On first initial run, hidden "on_unchange" callback.
        ### $on_unchange is lexical, so we can not "local"ize it.
        my $on_unchange_stash = $on_unchange;

 view all matches for this distribution


AnyEvent-Mattermost

 view release on metacpan or  search on metacpan

lib/AnyEvent/Mattermost.pm  view on Meta::CPAN


    $mconn->ping();

Pings the Mattermost server over the WebSocket connection to maintain online
status and ensure the connection remains alive. You should not have to call
this method yourself, as start() sets up a ping callback on a timer for you.

=cut

sub ping {
    my ($self) = @_;

 view all matches for this distribution


AnyEvent-Memcached

 view release on metacpan or  search on metacpan

examples/incadd.pl  view on Meta::CPAN

		servers   => [ '127.0.0.1:11211' ],
		namespace => "test:",
	);
	push @clients,$memd;
}
my $t;$t = AE::timer 0,1,sub {
	# every secons one clients will delete a key
	$clients[0]->delete('key1', cb => sub {
		defined $_[0] or warn "delete failed: $_[1]";
		warn $_[0];
	});

examples/incadd.pl  view on Meta::CPAN

	
	# and we run deleter, that will make thing "bad"
	my $deleter;$deleter = sub {
		$clients[0]->delete('key1',cb => sub {
			warn "deleted = @_";
			my $wait;$wait = AE::timer 0,0,sub {
				undef $wait;
				$deleter->();
			};
		});
	};$deleter->();

 view all matches for this distribution


AnyEvent-MockTCPServer

 view release on metacpan or  search on metacpan

lib/AnyEvent/MockTCPServer.pm  view on Meta::CPAN


sub sleep {
  my ($self, $handle, $actions, $interval, $desc) = @_;
  print STDERR 'Sleeping for ', $interval, ' ', $desc, "\n" if DEBUG;
  my $w;
  $w = AnyEvent->timer(after => $interval,
                       cb => sub {
                         $self->next_action($handle, $actions);
                         undef $w;
                       });
}

 view all matches for this distribution


AnyEvent-Monitor-CPU

 view release on metacpan or  search on metacpan

lib/AnyEvent/Monitor/CPU.pm  view on Meta::CPAN

}

sub start {
  my $self = shift;

  $self->{timer} = AnyEvent->timer(
    after    => $self->{interval},
    interval => $self->{interval},
    cb       => sub { $self->_check_cpu },
  );

lib/AnyEvent/Monitor/CPU.pm  view on Meta::CPAN

  $self->reset_stats;  

  return;
}

sub stop       { delete $_[0]->{timer} }
sub is_running { $_[0]->{timer} }

sub usage   { return $_[0]->{usage} }
sub is_low  { return $_[0]->{state} == 1 }
sub is_high { return $_[0]->{state} == 0 }

 view all matches for this distribution


AnyEvent-Monitor

 view release on metacpan or  search on metacpan

lib/AnyEvent/Monitor.pm  view on Meta::CPAN

has on_softfail => ( is => "ro", isa => "CodeRef" );
has on_hardfail => ( is => "ro", isa => "CodeRef" );
has on_resume   => ( is => "ro", isa => "CodeRef" );
has on_fatal    => ( is => "ro", isa => "CodeRef" );
has status      => ( is => "rw", isa => "Str", default => sub {''} );
has timer       => ( is => 'ro', isa => 'HashRef', default => sub { {} } );
has soft_timeout => ( is => 'rw', isa => 'Num', default => sub { 10 } );
has hard_timeout => ( is => 'rw', isa => 'Num', default => sub { 45 } );

has fail_detected => ( is => 'rw', isa => 'Num' );

method BUILD {
    $self->install_timers(0);
};

method install_timers($delay) {
    $self->install_timer( soft => $delay + $self->soft_timeout );
    $self->install_timer( hard => $delay + $self->hard_timeout );
}

method install_timer($which, $after) {
    my $method = "${which}fail";
    $self->timer->{$which} = AnyEvent->timer(after => $after,
                                             cb => sub {
                                                 $self->fail_detected(AnyEvent->now) unless $self->fail_detected;
                                                 $self->$method();
                                             },
                                         );
}

method heartbeat($timestamp, $status) {
    if ($status eq 'normal') {
        $self->install_timers($timestamp - AnyEvent->now);
        if ($self->status ne 'normal') { 
            my $outage = $self->fail_detected ? AnyEvent->now - $self->fail_detected : 0;
            $self->fail_detected(0);

            $self->on_resume->($self->status, $outage);

lib/AnyEvent/Monitor.pm  view on Meta::CPAN


method hardfail {
    $self->status('hard timeout')
        if $self->status eq 'normal';
    $self->on_hardfail->(sub {
                             $self->install_timers(shift || 60)
                                 unless $self->status eq 'normal'
                             });
}

__PACKAGE__->meta->make_immutable;

lib/AnyEvent/Monitor.pm  view on Meta::CPAN

          if ($prev) {
              warn "service resumed from: $prev, total outage: $outage secs";
          }
      });

  $foo->install_timers( 300 ); # delay checking for 300 secs

  sub my_polling_check {
      my ($timestamp, $status) = @_;
      # $foo->heartbeat($timestamp, $status);
  }

lib/AnyEvent/Monitor.pm  view on Meta::CPAN


=head1 METHODS

=over

=item install_timers($delay)

Set the next checking timer according to C<soft_timeout> and
C<hard_timeout>, with additional C<$delay> from now.  You don't
normally need to call this method manually, unless you want to delay
the start of the monitoring.

=item heartbeat($timestamp, $status)

 view all matches for this distribution


AnyEvent-MultiDownload

 view release on metacpan or  search on metacpan

lib/AnyEvent/MultiDownload.pm  view on Meta::CPAN

            my $status = $hdr->{Status};
            # on_body 正常的下载
            return if ( $hdr->{OrigStatus} and $hdr->{OrigStatus} == 200 ) or $hdr->{Status} == 200 or $hdr->{Status} == 416;

            if ( ($status == 500 or $status == 503 or $status =~ /^59/) and $retry < $self->max_retries ) {
                my $w; $w = AE::timer( $self->retry_interval, 0, sub {
                    $first_task->{pos}  = $first_task->{ofs}; # 重下本块时要 seek 回零
                    $first_task->{size} = 0;
                    $first_task->{ctx}  = undef;
                     $self->first_request(++$retry);
                    undef $w;

lib/AnyEvent/MultiDownload.pm  view on Meta::CPAN

        }
};

sub retry {
    my ($self, $task, $retry) = @_;
    my $w;$w = AE::timer( $self->retry_interval, 0, sub {
        $task->{pos}  = $task->{ofs}; # 重下本块时要 seek 回零
        $task->{size} = 0;
        $task->{ctx}  = undef;
        $self->fetch_block( $task, ++$retry );
        undef $w;

 view all matches for this distribution


AnyEvent-Multilog

 view release on metacpan or  search on metacpan

t/rotate.t  view on Meta::CPAN


$log->start;

# wait for exec
my $wait = AnyEvent->condvar;
my $t = AnyEvent->timer( after => 1, cb => $wait );
$wait->recv;

my $state = 0;
$log->run->delegate('input_handle')->handle->on_drain(sub {
    if($state < 10){

 view all matches for this distribution


AnyEvent-MySQL

 view release on metacpan or  search on metacpan

lib/AnyEvent/MySQL.pm  view on Meta::CPAN

}

sub _reconnect {
    my $dbh = shift;
    $dbh->{_}[CONN_STATEi] = BUSY_CONN;
    my $retry; $retry = AE::timer .1, 0, sub {
        undef $retry;
        _connect($dbh);
    };
}

 view all matches for this distribution


AnyEvent-Net-Curl-Queued

 view release on metacpan or  search on metacpan

inc/Test/HTTP/AnyEvent/Server.pm  view on Meta::CPAN

}


sub _reply {
    my ($h, $req, $hdr, $content) = @_;
    state $timer = {};

    my $res = HTTP::Response->new(
        200 => 'OK',
        HTTP::Headers->new(
            Connection      => 'close',

inc/Test/HTTP/AnyEvent/Server.pm  view on Meta::CPAN

                );
            } when (m{^/echo/body$}x) {
                $res->content($content);
            } when (m{^/delay/(\d+)$}x) {
                $res->content(sprintf(qq(issued %s\n), scalar gmtime));
                $timer->{$h} = AE::timer $1, 0, sub {
                    delete $timer->{$h};
                    AE::log debug => "delayed response\n";
                    $h->push_write($res->as_string("\015\012"));
                    _cleanup($h);
                };
                return;

 view all matches for this distribution


AnyEvent-Net-MPD

 view release on metacpan or  search on metacpan

t/example/chat.pl  view on Meta::CPAN


# Check for messages every X seconds
my $interval = 1;

# Check for messages in channels this account is subscribed to
my $timer = AnyEvent->timer(
  after => 1,
  interval => $interval,
  cb => sub {
    # We check for messages for all accounts
    foreach my $name (keys %accounts) {

 view all matches for this distribution


AnyEvent-Open3-Simple

 view release on metacpan or  search on metacpan

t/anyevent_open3_simple__mojo.t  view on Meta::CPAN


$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';

isnt(Mojo::Reactor->detect, 'Mojo::Reactor::EV', "Mojo::Reactor->detect = @{[ Mojo::Reactor->detect ]}");

Mojo::IOLoop->timer( 7 => sub {
  Mojo::IOLoop->stop;
  fail 'called on_exit';
});

my $called_on_start = 0;

 view all matches for this distribution


AnyEvent-Pg

 view release on metacpan or  search on metacpan

lib/AnyEvent/Pg.pm  view on Meta::CPAN

        delete $self->{timeout_watcher};
        $debug and $debug & 1 and $self->_debug("goto $goto");
        $self->$goto;
    }
    elsif ($self->{timeout}) {
        $self->{timeout_watcher} = AE::timer $self->{timeout}, 0, weak_method_callback_cached($self, '_connectPollTimeout');
    }
}

sub _connectPollTimeout {
    my $self = shift;

lib/AnyEvent/Pg.pm  view on Meta::CPAN

                    shift @$queries;
                    next;
                }
                $debug and $debug & 1 and $self->_debug("want to write query");
                $self->{write_watcher} = AE::io $self->{fd}, 1, weak_method_callback_cached($self, '_on_push_query_writable');
                $self->{timeout_watcher} = AE::timer $self->{timeout}, 0, weak_method_callback_cached($self, '_on_timeout')
                    if $self->{timeout};
                return;
            }

            if (delete $self->{call_on_empty_queue}) {

lib/AnyEvent/Pg.pm  view on Meta::CPAN

        $self->_on_consume_input;
    }
    elsif ($flush == 1) {
        $debug and $debug & 1 and $self->_debug("wants to write");
        $self->{write_watcher} = $ww // AE::io $self->{fd}, 1, weak_method_callback_cached($self, '_on_push_query_flushable');
        $self->{timeout_watcher} = AE::timer $self->{timeout}, 0, weak_method_callback_cached($self, '_on_timeout')
            if $self->{timeout};
    }
    else {
        die "internal error: flush returned $flush";
    }

lib/AnyEvent/Pg.pm  view on Meta::CPAN

        while (1) {
            if ($self->{write_watcher} or $dbc->busy) {
                $debug and $debug & 1 and $self->_debug($self->{write_watcher}
                                                        ? "wants to write and read"
                                                        : "wants to read");
                $self->{timeout_watcher} = AE::timer $self->{timeout}, 0, weak_method_callback_cached($self, '_on_timeout')
                    if $self->{timeout};
                return;
            }
            else {
                $debug and $debug & 1 and $self->_debug("data available");

 view all matches for this distribution


( run in 1.111 second using v1.01-cache-2.11-cpan-49f99fa48dc )