AnyEvent-Delay

 view release on metacpan or  search on metacpan

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


=head1 NAME

AnyEvent::Delay - Manage AnyEvent callbacks and control the flow of events

=head1 SYNOPSIS

    # Synchronize multiple events
    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;

    # Sequentialize multiple events
    my $cv = AE::cv;
    my $delay = AnyEvent::Delay->new();
    $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 {
          my ($delay, @args) = @_;
          say 'And done after 5 seconds total.';
          $cv->send;
        }
    );
    $cv->recv;

=head1 DESCRIPTION

L<AnyEvent::Delay> manages callbacks and controls the flow of events for L<AnyEvent>. This module is L<Mojo::IOLoop::Delay> version of AnyEvent. 

=head1 EVENTS



( run in 1.853 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )