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


AnyEvent-Delay-Simple

 view release on metacpan or  search on metacpan

lib/AnyEvent/Delay/Simple.pm  view on Meta::CPAN


    sub {
        my $cv = pop();
        $cv->begin();
        $cv->begin();
        my $w1; $w1 = AE::timer 1.0, 0, sub { $cv->end(); undef($w1); };
        my $w2; $w2 = AE::timer 2.0, 0, sub { $cv->end(); undef($w2); };
        $cv->cb(sub { $cv->send('step finished'); });
    }

=head2 easy_delay

 view all matches for this distribution


AnyEvent-Digest

 view release on metacpan or  search on metacpan

t/02-async-idle.t  view on Meta::CPAN

my $our;
lives_ok { $our = AnyEvent::Digest->new('Digest::MD5') } 'construction';

my $interval = $ENV{TEST_ANYEVENT_DIGEST_INTERVAL} || 0.01;
my $count = 0;
my $w; $w = AE::timer 0, $interval, sub {
    ++$count;
};

my $cv = AE::cv;
$our->addfile_async($fh)->cb(sub {

 view all matches for this distribution


AnyEvent-Discord-Client

 view release on metacpan or  search on metacpan

lib/AnyEvent/Discord/Client.pm  view on Meta::CPAN

    roles => {},

    gateway => undef,
    conn => undef,
    websocket => undef,
    heartbeat_timer => undef,
    last_seq => undef,
    reconnect_delay => 1,
  };

  die "cannot construct new $class without a token parameter" unless defined $self->{token};

lib/AnyEvent/Discord/Client.pm  view on Meta::CPAN


      if ($msg->{op} == 0) { #dispatch
        print "\e[1;30mdispatch event $msg->{t}:".Dumper($msg->{d})."\e[0m\n" if $debug;
        $event_handler{$msg->{t}}($self, $msg->{d}) if $event_handler{$msg->{t}};
      } elsif ($msg->{op} == 10) { #hello
        $self->{heartbeat_timer} = AnyEvent->timer(
          after => $msg->{d}{heartbeat_interval}/1e3,
          interval => $msg->{d}{heartbeat_interval}/1e3,
          cb => sub {
            $self->websocket_send(1, $self->{last_seq});
          },

lib/AnyEvent/Discord/Client.pm  view on Meta::CPAN

    });

    $self->{conn}->on(finish => sub {
      my($connection) = @_;
      print "Disconnected! Reconnecting in five seconds...\n";
      my $reconnect_timer; $reconnect_timer = AnyEvent->timer(
        after => $self->{reconnect_delay},
        cb => sub {
          $self->connect();
          $reconnect_timer = undef;
        },
      );
    });
  });
}

lib/AnyEvent/Discord/Client.pm  view on Meta::CPAN

  $self->api(POST => "/channels/$channel_id/messages", {content => $message});
}

sub typing {
  my ($self, $channel) = @_;
  return AnyEvent->timer(
    after => 0,
    interval => 5,
    cb => sub {
      $self->api(POST => "/channels/$channel->{id}/typing", '');
    },

 view all matches for this distribution


AnyEvent-Discord

 view release on metacpan or  search on metacpan

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

  has _events => ( is => 'ro', isa => HashRef, default => sub { {} } );
  # Internal-defined event handlers
  has _internal_events => ( is => 'ro', isa => HashRef, builder => '_build_internal_events' );
  # WebSocket
  has _socket => ( is => 'rw' );
  # Heartbeat timer
  has _heartbeat => ( is => 'rw' );
  # Last Sequence
  has _sequence => ( is => 'rw', isa => Num, default => 0 );
  # True if caller manually disconnected, to avoid reconnection
  has _force_disconnect => ( is => 'rw', isa => Bool, default => 0 );

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

        $self->_handle_internal_event('disconnected');
        unless ($self->_force_disconnect()) {
          my $seconds = $self->_backoff->failure();
          $self->_debug('Reconnecting in ' . $seconds);
          my $reconnect;
          $reconnect = AnyEvent->timer(
            after => $seconds,
            cb    => sub {
              $self->connect();
              $reconnect = undef;
              AnyEvent->condvar->send();

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

  method send($channel_id, $content) {
    return $self->_discord_api('POST', 'channels/' . $channel_id . '/messages', encode_json({content => $content}));
  }

  method typing($channel_id) {
    return AnyEvent->timer(
      after    => 0,
      interval => 5,
      cb       => sub {
        $self->_discord_api('POST', 'channels/' . $channel_id . '/typing');
        AnyEvent->condvar->send();

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


  # Called when Discord provides the 'hello' event
  method _event_hello(AnyEvent::Discord::Payload $payload) {
    $self->_debug('Received hello event');
    my $interval = $payload->d->{'heartbeat_interval'};
    my $timer = AnyEvent->timer(
      after    => $interval * rand() / 1000,
      interval => $interval / 1000,
      cb       => sub {
        $self->_debug('Heartbeat');
        $self->_ws_send_payload(AnyEvent::Discord::Payload->from_hashref({

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

          d  => $self->_sequence()
        }));
        AnyEvent->condvar->send();
      }
    );
    $self->_heartbeat($timer);
  }

  # GUILD_CREATE event
  method _event_guild_create($client, HashRef $data, Num $opcode?) {
    $self->guilds->{$data->{'id'}} = $data->{'name'};

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

Send a message to the provided channel.

=item typing($channel_id)

Starts the "typing..." indicator in the provided channel. This method issues the
typing request, and starts a timer on the caller's behalf to keep the indicator
active. Returns an instance of that timer to allow the caller to undef it when
the typing indicator should be stopped.

  my $instance = $client->typing($channel);
  # ... perform some actions
  $instance = undef;

 view all matches for this distribution


AnyEvent-EditText

 view release on metacpan or  search on metacpan

samples/simple_example  view on Meta::CPAN

use AnyEvent::EditText;

# An AnyEvent condition variable, see perldoc AnyEvent
my $condvar = AnyEvent->condvar;

# Here just a simple periodic timer is generated which will
# print the ticks to stdout.
my $cnt = 0;
my $t;
my $timer; $timer = sub {
   $t = AnyEvent->timer (after => 1, cb => sub {
      print "Tick " . ($cnt++) . "\n";;
      $timer->();
   });
};
$timer->();

my $content = "This is\nA simple\nExample!\n";

AnyEvent::EditText::set_editor ('rxvt', '-e', 'vim');

 view all matches for this distribution


AnyEvent-Eris

 view release on metacpan or  search on metacpan

lib/AnyEvent/eris/Client.pm  view on Meta::CPAN

        my $hdl; $hdl = AnyEvent::Handle->new(
            fh       => $fh,
            on_error => sub {
                AE::log error => $_[2];
                $_[0]->destroy;
                $inner_self->{'_reconnect_timer'} = AE::timer 10, 0, sub {
                    undef $inner_self->{'_reconnect_timer'};
                    $inner_self->_connect;
                };
            },

            on_eof   => sub { $hdl->destroy; AE::log info => 'Done.' },

lib/AnyEvent/eris/Client.pm  view on Meta::CPAN

            },
        );

        $inner_self->{'buffer'} = '';

        # FIXME: should this really be in a timer?
        # all the actions relating to a socket are deferred anyway
        $inner_self->{'_setup_pipe_timer'} = AE::timer 0, 0, sub {
            undef $inner_self->{'_setup_pipe_timer'};
            $inner_self->setup_pipe($hdl);
        };
    };

    return $self;

 view all matches for this distribution


AnyEvent-FCGI

 view release on metacpan or  search on metacpan

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

                'Content-Type' => 'text/plain',
            );
        }
    );

    my $timer = AnyEvent->timer(
        after => 10,
        interval => 0,
        cb => sub {
            # shut down server after 10 seconds
            $fcgi = undef;

 view all matches for this distribution


AnyEvent-FCP

 view release on metacpan or  search on metacpan

FCP.pm  view on Meta::CPAN

   }, $class;

   {
      Scalar::Util::weaken (my $self = $self);

      $self->{kw} = AE::timer $self->{keepalive}, $self->{keepalive}, sub {
         $self->{hdl}->push_write ("\n");
      };

      our $ENDMESSAGE = qr<\012(EndMessage|Data)\012>;

 view all matches for this distribution


AnyEvent-FDpasser

 view release on metacpan or  search on metacpan

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


  $self->{full_descriptor_table_state} = 1;

  undef $self->{iwatcher};

  my $watcher; $watcher = AE::timer 0.05, 0.5, sub {
    $self->setup_fh_duped;
    if (exists $self->{fh_duped}) {
      undef $watcher;
      delete $self->{full_descriptor_table_state};
      $self->try_to_recv;

 view all matches for this distribution


AnyEvent-FTP

 view release on metacpan or  search on metacpan

lib/AnyEvent/FTP/Client/Transfer/Active.pm  view on Meta::CPAN


    my($fh, $host, $port) = @_;
    my $ip_and_port = join(',', split(/\./, $self->client->{my_ip}), $port >> 8, $port & 0xff);

    my $w;
    $w = AnyEvent->timer(after => 0, cb => sub {
      $self->push_command(
        [ PORT => $ip_and_port ],
        ($self->restart > 0 ? ([ REST => $self->restart ]) : ()),
        $self->command,
      );

 view all matches for this distribution


AnyEvent-FastPing

 view release on metacpan or  search on metacpan

FastPing.pm  view on Meta::CPAN

If your idle callback were called instantly after all ranges were
exhausted and you destroyed the object inside (which is common), then
there would be no chance to receive some replies, as there would be no
time of the packet to travel over the network.

This can be fixed by starting a timer in the idle callback, or more simply
by selecting a suitable C<max_rtt> value, which should be the maximum time
you allow a ping packet to travel to its destination and back.

The pinger thread automatically waits for this amount of time before becoming idle.

 view all matches for this distribution


AnyEvent-Feed

 view release on metacpan or  search on metacpan

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

      }

      my $wself = $self;
      weaken $wself;

      $self->{timer_cb} = sub {
         $wself->fetch (sub {
            my ($self, $e, $f, $err) = @_;

            $self->{on_fetch}->($self, $e, $f, $err);

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

      $self->{timer_cb}->();
   }

   return $self
}

 view all matches for this distribution


AnyEvent-FileLock

 view release on metacpan or  search on metacpan

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

           (!defined($self->{max_time}) or $self->{max_time} >= $now)) {
        # we add some randomness into the delay to avoid the case
        # where all the contenders follow exactly the same pattern so
        # that they end looking for the pattern all at once every time
        # (and obviosly all but one failing).
        $self->{timer} = &AE::timer($self->{delay} * (0.8 + rand 0.40), 0, $self->{acquire_lock_cb});
        return;
    }
    else {
        $self->{user_cb}->();
    }

 view all matches for this distribution


AnyEvent-Filesys-Notify

 view release on metacpan or  search on metacpan

lib/AnyEvent/Filesys/Notify.pm  view on Meta::CPAN

moderately sized directories). The use of the KQueue backend is discouraged.

=head2 Fallback

A simple scan of the watched directories at regular intervals. Sets up an
C<AnyEvent-E<gt>timer> watcher which is executed every C<interval> seconds
(or fractions thereof). C<interval> can be specified in the constructor to
L<AnyEvent::Filesys::Notify> and defaults to 2.0 seconds.

This is a very inefficient implementation. Use one of the others if possible.

lib/AnyEvent/Filesys/Notify.pm  view on Meta::CPAN

functionality those modules provide into an event framework. Neither of the
existing modules seem to work with well with an event loop.
L<Filesys::Notify::Simple> does not supply a non-blocking interface and
L<File::ChangeNotify> requires you to poll an method for new events. You could
fork off a process to run L<Filesys::Notify::Simple> and use an event handler
to watch for notices from that child, or setup a timer to check
L<File::ChangeNotify> at regular intervals, but both of those approaches seem
inefficient or overly complex. Particularly, since the underlying watcher
implementations (L<Mac::FSEvents> and L<Linux::INotify2>) provide a filehandle
that you can use and IO event to watch.

 view all matches for this distribution


AnyEvent-Filesys-Watcher

 view release on metacpan or  search on metacpan

lib/AnyEvent/Filesys/Watcher/Fallback.pm  view on Meta::CPAN

	my ($class, %args) = @_;

	my $self = $class->SUPER::_new(%args);

	my $alter_ego = $self;
	my $impl = AnyEvent->timer(
		after => $self->interval,
		interval => $self->interval,
		cb => sub {
			$alter_ego->_processEvents();
		}
	);
	weaken $alter_ego;

	if (!$impl) {
		die __x("Error creating timer: {error}\n", error => $@);
	}

	$self->_watcher($impl);

	return $self;

 view all matches for this distribution


AnyEvent-Finger

 view release on metacpan or  search on metacpan

t/simple.t  view on Meta::CPAN

use warnings;
use Test::More tests => 3;
use AnyEvent;
use AnyEvent::Finger qw( finger_server finger_client );

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

my $port = eval {

 view all matches for this distribution


AnyEvent-Fork-Pool

 view release on metacpan or  search on metacpan

Pool.pm  view on Meta::CPAN

The default of C<2> is usually a good compromise.

=item start => $seconds (default: 0.1)

When there are fewer than C<idle> workers (or all workers are completely
busy), then a timer is started. If the timer elapses and there are still
jobs that cannot be queued to a worker, a new worker is started.

This sets the minimum time that all workers must be busy before a new
worker is started. Or, put differently, the minimum delay between starting
new workers.

Pool.pm  view on Meta::CPAN

   };

   $want_start = sub {
      undef $stop_w;

      $start_w ||= AE::timer $start, $start, sub {
         if (($nidle < $idle || @queue) && @pool < $max) {
            $start_worker->();
            $scheduler->();
         } else {
            undef $start_w;
         }
      };
   };

   $want_stop = sub {
      $stop_w ||= AE::timer $stop, $stop, sub {
         $stop_worker->($pool[0])
            if $nidle;

         undef $stop_w
            if $nidle <= $idle;

 view all matches for this distribution


AnyEvent-Fork-RPC

 view release on metacpan or  search on metacpan

RPC.pm  view on Meta::CPAN

you really I<are> done.

=head2 Example 2: Asynchronous Backend

This example implements multiple count-downs in the child, using
L<AnyEvent> timers. While this is a bit silly (one could use timers in the
parent just as well), it illustrates the ability to use AnyEvent in the
child and the fact that responses can arrive in a different order then the
requests.

It also shows how to embed the actual child code into a C<__DATA__>
section, so it doesn't need any external files at all.

And when your parent process is often busy, and you have stricter timing
requirements, then running timers in a child process suddenly doesn't look
so silly anymore.

Without further ado, here is the code:

   use AnyEvent;

RPC.pm  view on Meta::CPAN


      my $n;

      AnyEvent::Fork::RPC::event "starting to count up to $count\n";

      my $w; $w = AE::timer 1, 1, sub {
         ++$n;

         AnyEvent::Fork::RPC::event "count $n of $count\n";

         if ($n == $count) {

RPC.pm  view on Meta::CPAN

It then starts three countdowns, from 3 to 1 seconds downwards, destroys
the rpc object so the example finishes eventually, and then just waits for
the stuff to trickle in.

The worker code uses the event function to log some progress messages, but
mostly just creates a recurring one-second timer.

The timer callback increments a counter, logs a message, and eventually,
when the count has been reached, calls the finish callback.

On my system, this results in the following output. Since all timers fire
at roughly the same time, the actual order isn't guaranteed, but the order
shown is very likely what you would get, too.

   starting to count up to 3
   starting to count up to 2

 view all matches for this distribution


AnyEvent-ForkObject

 view release on metacpan or  search on metacpan

t/01_fo.t  view on Meta::CPAN

            }
        );
    });


    my $timer = AE::timer 0.01, 0.01 => sub {
        return if $phase < 5;
        undef $obj; $cv->send
    };

    my $timeout; $timeout =
        AE::timer 2, 0 => sub { undef $obj; undef $timeout; $cv->send  };

    $cv->recv;

    ok $timeout, "Timeout wasn't reached";
}

t/01_fo.t  view on Meta::CPAN


                });
            });
    });

    my $timer = AE::timer 1, 0 => sub {  $cv->send };

    $cv->recv;
}

{

t/01_fo.t  view on Meta::CPAN

    kill KILL => $obj->{pid};
    waitpid $obj->{pid}, 0;
    $obj->do(require => 'Data::Dumper', cb => sub {
        diag explain \@_ unless  ok $_[0] eq 'fatal', 'Child was killed';
        my $t;
        $t = AE::timer 0.3, 0 => sub {
            undef $t;
            $cv->send;
        }
    });

t/01_fo.t  view on Meta::CPAN

        $dont_call_if_destroyed = 0;
    });
    kill KILL => $obj2->{pid};
    undef $obj2;

    my $timeout; $timeout = AE::timer 1, 0 => sub { undef $timeout; $cv->send };

    $cv->recv;

    ok $dont_call_if_destroyed, "Don't touch callbacks if destroyed";
    ok $timeout, "Timeout wasn't reached";

t/01_fo.t  view on Meta::CPAN

                    });
                });
            });
        });

    my $timer = AE::timer 0.5, 0 => sub {  $cv->send };

    $cv->recv;
}

 view all matches for this distribution


AnyEvent-Future

 view release on metacpan or  search on metacpan

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

=head2 new_timeout

   $f = AnyEvent::Future->new_timeout( @args )

Returns a new leaf future instance that will become ready at the time given by
the arguments, which will be passed to the C<< AnyEvent->timer >> method.

C<new_delay> returns a future that will complete successfully at the alotted
time, whereas C<new_timeout> returns a future that will fail with the message
C<Timeout>. This is provided as a simple utility for small use-cases; for a
more find-grained control over the failure message and additional values you

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

   shift;
   my %args = @_;

   as_future {
      my $f = shift;
      AnyEvent->timer( %args, cb => sub { $f->done } );
   };
}

sub new_timeout
{
   shift;
   my %args = @_;

   as_future {
      my $f = shift;
      AnyEvent->timer( %args, cb => sub { $f->fail( "Timeout" ) } );
   };
}

=head2 from_cv

 view all matches for this distribution


AnyEvent-GPSD

 view release on metacpan or  search on metacpan

GPSD.pm  view on Meta::CPAN

      @_,
      interval => 1,
      fix      => { time => AnyEvent->now, mode => 1 },
   }, $class;

   $self->interval_timer;
   $self->connect;

   $self
}

GPSD.pm  view on Meta::CPAN


   delete $self->{fh};
   delete $self->{command};

   Scalar::Util::weaken $self;
   $self->{retry_w} = AnyEvent->timer (after => 1, cb => sub {
      delete $self->{retry_w};
      $self->connect;
   });
}

# make sure we send "no fix" updates when we lose connectivity
sub interval_timer {
   my ($self) = @_;

   $self->{interval_w} = AnyEvent->timer (after => $self->{interval}, cb => sub {
      if (AnyEvent->now - $self->{fix}{time} > $self->{interval} * 1.9) {
         $self->{fix}{mode} = 1;
         $self->event (fix => $self->{fix});
      }

      $self->interval_timer;
   });

   Scalar::Util::weaken $self;
}

GPSD.pm  view on Meta::CPAN

                   and $self->{fix} && ($self->{fix}{mode} < 2 || $self->{fix}{speed} < $self->{min_speed}))
            ) {
               $self->{replay_now} = $time;
            }

            $self->{replay_timer} = AnyEvent->timer (after => $time - $self->{replay_now}, cb => sub {
               $self->{replay_now} = $time;
               $self->{command} = []; # no can do
               $self->feed ($data[0]) if $type eq "raw";
               $self->{replay_cb}();
            });

GPSD.pm  view on Meta::CPAN

      $self->{replay_cb}();

   } else {
      delete $self->{stretch};
      delete $self->{compress};
      delete $self->{replay_timer};
      delete $self->{replay_cb};
   }
}

=back

 view all matches for this distribution


AnyEvent-Gearman-WorkerPool

 view release on metacpan or  search on metacpan

lib/AnyEvent/Gearman/WorkerPool.pm  view on Meta::CPAN

        my $min = $conf->{min};
        foreach my $i ( 0 .. $min-1 ){
            $slots->[$i]->start();
        }
    }
    my $iw = AE::timer 0,5, sub{$self->on_idle;};
    $self->idle_watcher($iw);
}

sub on_idle{
    my $self = shift;

lib/AnyEvent/Gearman/WorkerPool.pm  view on Meta::CPAN


	sub slowreverse{
        DEBUG 'slowreverse';
        my $self = shift;
        my $job = shift;
        my t = AE::timer 1,0, sub{
            my $res = reverse($job->workload);
            $job->complete( $res );
        };
    }
    sub reverse{

 view all matches for this distribution


AnyEvent-Gearman

 view release on metacpan or  search on metacpan

lib/AnyEvent/Gearman/Worker.pm  view on Meta::CPAN

For example:

    $worker->register_function( reverse => sub {
        my $job = shift;

        my $t; $t = AnyEvent->timer(
            after => 10,
            cb    => sub {
                undef $t;
                $job->complete('done!');
            },

 view all matches for this distribution


AnyEvent-Git-Wrapper

 view release on metacpan or  search on metacpan

t/basic_nb.t  view on Meta::CPAN

use POSIX qw(strftime);
use Sort::Versions;
use Test::Deep;
use Test::Exception;

#my $global_timeout = AE::timer 30, 0, sub { say STDERR "TIMEOUT!"; exit 2 };

my $dir = tempdir(CLEANUP => 1);

my $git = AnyEvent::Git::Wrapper->new($dir);

t/basic_nb.t  view on Meta::CPAN

    IO::File->new(">" . File::Spec->catfile($dir, qw(second_commit)))->print("second_commit\n");
    $git->add('second_commit', AE::cv)->recv;

    do {
      my $cv = AE::cv;
      my $w = AE::timer 5, 0, sub { $cv->send(0) };
      $git->commit(sub { $cv->send(1)});
      ok $cv->recv, 'Attempt to commit interactively fails quickly';
    };
    
    my $error;
    my $timeout = do {
      my $cv = AE::cv;
      my $w = AE::timer 5, 0, sub { $cv->send(1) };
      $git->commit({ message => "", 'allow-empty-message' => 1 }, sub { $error = $@ unless eval { shift->recv }; $cv->send(0) });
      $cv->recv;
    };

    if ( $error && !$timeout ) {

 view all matches for this distribution


AnyEvent-Gmail-Feed

 view release on metacpan or  search on metacpan

lib/AnyEvent/Gmail/Feed.pm  view on Meta::CPAN

    my $uri = 'https://mail.google.com/mail/feed/atom/';
    $uri .= $label . '/' if $label; ## 'unread' or whatever

    my %seen;

    my $timer;
    my $checker; $checker = sub {
        http_get $uri, headers => $headers, sub {
            my ($body, $hdr) = @_;
            return unless $body;
            my $feed = XML::Atom::Feed->new(\$body) or return;

lib/AnyEvent/Gmail/Feed.pm  view on Meta::CPAN

                unless ($seen{$e->id}) {
                    ($args{on_new_entry} || sub {})->($e);
                };
                $seen{$e->id}++;
            }
            $timer = AnyEvent->timer( after => $interval, cb => $checker);
        };
    };
    $checker->();
    return $self;
}

 view all matches for this distribution


AnyEvent-Graphite

 view release on metacpan or  search on metacpan

lib/AnyEvent/Graphite/SNMPAgent.pm  view on Meta::CPAN

        snmp_version => $snmp_version,
        %args,
    }, $class;

       
    # start the timer running
    $self->{timer} = AE::timer 0, $interval, sub { $self->gather_metrics; }; 

    return $self;
}

sub add_snmp {

lib/AnyEvent/Graphite/SNMPAgent.pm  view on Meta::CPAN

        my (@addrs) = @_;
        push(@{$self->{hosts}{$addrs[0]}}, \%arg); 
    };
}

# this is called by $self->{timer} every $interval seconds
sub gather_metrics {
    my ($self) = @_;
    for my $host (keys %{$self->{hosts}}) {

        # skip any hosts that did not resolve

 view all matches for this distribution


AnyEvent-Groonga

 view release on metacpan or  search on metacpan

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

sub _set_timeout {
    my $self    = shift;
    my $cv      = shift;
    my $timeout = shift;
    AnyEvent->now_update;
    my $timer;
    $timer = AnyEvent->timer(
        after => $timeout,
        cb    => sub {
            my $data = [ [ 0, undef, undef, ], ['timeout'] ];
            my $result = AnyEvent::Groonga::Result->new( data => $data );
            $cv->send($result);
            undef $timer;
        },
    );
}

sub _post_to_http_server {

 view all matches for this distribution


AnyEvent-HTTP-MXHR

 view release on metacpan or  search on metacpan

t/001_basic.t  view on Meta::CPAN


test_tcp(
    server => sub {
        my $port = shift;

        my $apoptosis; $apoptosis = AE::timer 60, 0, sub {
            kill TERM => $$;
            undef $apoptosis;
        };

        my $server = tcp_server undef, $port, sub {

t/001_basic.t  view on Meta::CPAN


            my $i = 1;
            # XXX for some reaason it seems like fork-then-start anyevent
            # has a weird side effect where a watcher's first invocation
            # is executed twice...?
            my $w; $w = AE::timer 1, 1, sub {
                $handle->push_write(
                    "Content-Type: application/json\r\n\r\n" .
                    qq|{ "foo": "bar", "bar": "baz", "seq": $i }| . "\n" .
                    "--AAABBBCCC"
                );

t/001_basic.t  view on Meta::CPAN

        $cv->recv;
    },
    client => sub {
        my $port = shift;

        my $apoptosis; $apoptosis = AE::timer 60, 0, sub {
            kill TERM => $$;
            undef $apoptosis;
        };
        my $seq = 1;
        my $guard;

 view all matches for this distribution


AnyEvent-HTTP-Socks

 view release on metacpan or  search on metacpan

lib/AnyEvent/HTTP/Socks.pm  view on Meta::CPAN

			push @chain, {ver => $1, login => $2, pass => $3, host => $4, port => $5};
		}
		
		if (@chain) {
			$opts{tcp_connect} = sub {
				my ($cv, $watcher, $timer, $sock);
				my @tmp_chain = @chain; # copy: on redirect @tmp_chain will be already empty
				_socks_prepare_connection(\$cv, \$watcher, \$timer, $sock, \@tmp_chain, @_);
			};
		}
		else {
			croak 'unsupported socks address specified';
		}

lib/AnyEvent/HTTP/Socks.pm  view on Meta::CPAN

	my ($class, $where) = @_;
	$class->export($where, @EXPORT);
}

sub _socks_prepare_connection {
	my ($cv, $watcher, $timer, $sock, $chain, $c_host, $c_port, $c_cb, $p_cb) = @_;
	
	unless ($sock) { # first connection in the chain
		# XXX: need also support IPv6 when SOCKS host is a domain name, but this is not so easy
		socket(
			$sock,

lib/AnyEvent/HTTP/Socks.pm  view on Meta::CPAN

			getprotobyname('tcp')
		)
		or return $c_cb->();
			
		my $timeout = $p_cb->($sock);
		$$timer = AnyEvent->timer(
			after => $timeout,
			cb => sub {
				undef $$watcher;
				undef $$cv;
				$! = Errno::ETIMEDOUT;

lib/AnyEvent/HTTP/Socks.pm  view on Meta::CPAN

		
		$_->{host} =~ s/^\[// and $_->{host} =~ s/\]$// for @$chain;
	}
	
	$$cv = AE::cv {
		_socks_connect($cv, $watcher, $timer, $sock, $chain, $c_host, $c_port, $c_cb);
	};
	
	$$cv->begin;
	
	$$cv->begin;

lib/AnyEvent/HTTP/Socks.pm  view on Meta::CPAN

	
	return $sock;
}

sub _socks_connect {
	my ($cv, $watcher, $timer, $sock, $chain, $c_host, $c_port, $c_cb) = @_;
	my $link = shift @$chain;
	
	my @specopts;
	if ($link->{ver} eq '4a') {
		$link->{ver} = 4;

lib/AnyEvent/HTTP/Socks.pm  view on Meta::CPAN

	                                  ('w', WRITE_WATCHER);
	
	$$watcher = AnyEvent->io(
		fh => $sock,
		poll => $poll,
		cb => sub { _socks_handshake($cv, $watcher, $w_type, $timer, $sock, $chain, $c_host, $c_port, $c_cb) }
	);
}

sub _socks_handshake {
	my ($cv, $watcher, $w_type, $timer, $sock, $chain, $c_host, $c_port, $c_cb) = @_;
	
	if ($sock->ready) {
		undef $$watcher;
		
		if (@$chain) {
			return _socks_prepare_connection($cv, $watcher, $timer, $sock, $chain, $c_host, $c_port, $c_cb);
		}
		
		undef $$timer;
		return $c_cb->($sock);
	}
	
	if ($SOCKS_ERROR == SOCKS_WANT_WRITE) {
		if ($w_type != WRITE_WATCHER) {
			undef $$watcher;
			$$watcher = AnyEvent->io(
				fh => $sock,
				poll => 'w',
				cb => sub { _socks_handshake($cv, $watcher, WRITE_WATCHER, $timer, $sock, $chain, $c_host, $c_port, $c_cb) }
			);
		}
	}
	elsif ($SOCKS_ERROR == SOCKS_WANT_READ) {
		if ($w_type != READ_WATCHER) {
			undef $$watcher;
			$$watcher = AnyEvent->io(
				fh => $sock,
				poll => 'r',
				cb => sub { _socks_handshake($cv, $watcher, READ_WATCHER, $timer, $sock, $chain, $c_host, $c_port, $c_cb) }
			);
		}
	}
	else {
		# unknown error
		$@ = "IO::Socket::Socks: $SOCKS_ERROR";
		undef $$watcher;
		undef $$timer;
		$c_cb->();
	}
}

1;

 view all matches for this distribution


AnyEvent-HTTPD

 view release on metacpan or  search on metacpan

lib/AnyEvent/HTTPD/HTTPConnection.pm  view on Meta::CPAN

   return if $self->{disconnected};

   weaken $self;

   $self->{req_timeout} =
      AnyEvent->timer (after => $self->{request_timeout}, cb => sub {
         return unless defined $self;

         $self->do_disconnect ("request timeout ($self->{request_timeout})");
      });

lib/AnyEvent/HTTPD/HTTPConnection.pm  view on Meta::CPAN

   delete $self->{req_timeout};
   $self->event ('disconnect', $err);
   shutdown $self->{hdl}->{fh}, 1;
   $self->{hdl}->on_read (sub { });
   $self->{hdl}->on_eof (undef);
   my $timer;
   $timer = AE::timer 2, 0, sub {
      undef $timer;
      delete $self->{hdl};
   };
}

1;

 view all matches for this distribution


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