AnyEvent-Tools

 view release on metacpan or  search on metacpan

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



=head2 async_repeat(COUNT, CALLBACK [, DONE_CALLBACK ])

Repeats calling Your callback(s).

    async_repeat 10, sub { $count++ };
    async_repeat 20, sub { $count++ }, sub { $done = 1 };

The function async_repeat returns the guard if it is called in non-void
context. Destroy the guard if You want to cancel iterations.

Iteration callback receives the following arguments:

=over

=item 1. guard

The next iteration will not start until the guard is destroyed.

=item 2. iteration number

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


TRUE on the last iteration.

=back

=head2 async_for(HASREF|ARRAYREF, CALLBACK [, DONE_CALLBACK ]);

Calls Your callbacks for each array or hash element.

The function returns the guard if it is called in non-void
context. Destroy the guard if You want to cancel iterations.

If You process an array using the function, iteration callback
will receive the following arguments:

=over

=item 1. guard

The next iteration will not start until the guard is destroyed.

t/07_buffer.t  view on Meta::CPAN


    $cv->recv;

    ok @res == 4, "Flush buffer after overflow";
    my @time = (0.18, .38, .58, .78, .98);
    for my $i (0 .. 3) {
        my $delay = $res[$i]{time} - $start_time;
        my $count = @{ $res[$i]{obj} };
        ok $delay >= $time[$i], "$i flush was in time (count: $count)";
        ok $delay <  $time[$i + 1], "$i flush was in time (count: $count)";
        ok $count > 100, "A lot iterations were done";
        my $ok;
        for (0 .. $#{ $res[$i]{obj} } - 1) {
            $ok = $res[$i]{obj}[$_] > $res[$i]{obj}[$_ + 1];
            last unless $ok;
        }

        ok $ok, "$i sequence order is right (count: $count)";
    }
}



( run in 1.156 second using v1.01-cache-2.11-cpan-96521ef73a4 )