AnyEvent-Tools
view release on metacpan or search on metacpan
t/03_repeat.t view on Meta::CPAN
#!/usr/bin/perl
use warnings;
use strict;
use utf8;
use open qw(:std :utf8);
use lib qw(lib ../lib);
use Time::HiRes qw(time);
use Test::More tests => 16;
use Encode qw(decode encode);
BEGIN {
# ÐодгоÑовка обÑекÑа ÑеÑÑиÑÐ¾Ð²Ð°Ð½Ð¸Ñ Ð´Ð»Ñ ÑабоÑÑ Ñ utf8
my $builder = Test::More->builder;
binmode $builder->output, ":utf8";
binmode $builder->failure_output, ":utf8";
binmode $builder->todo_output, ":utf8";
use_ok 'AnyEvent';
use_ok 'AnyEvent::Tools', ':foreach';
}
{
my $cv = condvar AnyEvent;
my $count = 0;
async_repeat 0, sub { $count++ }, sub { $cv->send };
$cv->recv;
ok $count == 0, "Repeat 0 times";
}
{
my $cv = condvar AnyEvent;
my $count = 0;
async_repeat 0, sub { $count++ };
my $timer_end;
$timer_end = AE::timer 0.5, 0 => sub {
undef $timer_end;
$cv->send;
};
$cv->recv;
ok $count == 0, "Repeat 0 times without endfucntion";
}
{
my $cv = condvar AnyEvent;
my $count = 0;
async_repeat 10, sub { $count++ }, sub { $cv->send };
$cv->recv;
diag $count unless ok $count == 10, "Repeat 10 times";
}
{
my $cv = condvar AnyEvent;
my $count = 0;
async_repeat 10, sub {
$count++;
my ($g, $no, $first, $last) = @_;
$cv->send if $last;
};
$cv->recv;
( run in 0.453 second using v1.01-cache-2.11-cpan-39bf76dae61 )