Eixo-Rest
view release on metacpan or search on metacpan
t/030_request_async.t view on Meta::CPAN
);
$request_async->send($ua, undef);
#
# Waiting for the jobs to finish
#
$api->waitForJobs();
is(scalar(@chunks), $TIMES, 'Progress of request seems ok');
my %chunks = map {$_ => 1} @chunks;
is(scalar(grep { $chunks{'CHUNK_' .$_} } (1..$TIMES)), $TIMES, 'Type of progress seems all right');
is($end, 'OK', 'The request ended well');
}
done_testing();
package FakeApi;
sub new{
bless({jobs=>[]});
}
sub newJob{
push @{$_[0]->{jobs}}, $_[1];
}
sub jobFinished{
$_[0]->{jobs} = [grep { $_ != $_[1]} @{$_[0]->{jobs}}];
}
sub waitForJobs{
while(scalar(@{$_[0]->{jobs}})){
foreach(@{$_[0]->{jobs}}){
$_->process;
select(undef, undef, undef, 0.05);
}
}
}
package FakeUserAgent;
sub new{
return bless({t=>$_[1], success=>$_[2], content=>$_[3] || $_[2]});
}
sub is_success{
return $_[0]->{success};
}
sub decoded_content{
return $_[0]->{content};
}
sub content_type{
'application/json'
}
sub request{
my ($self, $req, $code) = @_;
for(1..$self->{t}){
$code->('CHUNK_' . $_, $self);
select(undef,undef,undef,0.25);
}
$self;
}
( run in 1.052 second using v1.01-cache-2.11-cpan-5837b0d9d2c )