Skip to content

Commit 5a7e309

Browse files
committed
Improve speed of attempt() and make callback optional
1 parent 495682a commit 5a7e309

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

  • t/lib/Mojo/IOLoop/ReadWriteProcess/Test

t/lib/Mojo/IOLoop/ReadWriteProcess/Test/Utils.pm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
package Mojo::IOLoop::ReadWriteProcess::Test::Utils;
22

33
our @EXPORT_OK = qw(attempt);
4-
4+
use Time::HiRes qw(sleep);
55
use Exporter 'import';
66
use constant DEBUG => $ENV{MOJO_PROCESS_DEBUG};
77

88
sub attempt {
99
my $attempts = 0;
1010
my ($total_attempts, $condition, $cb, $or)
1111
= ref $_[0] eq 'HASH' ? (@{$_[0]}{qw(attempts condition cb or)}) : @_;
12+
$cb //= sub {1};
1213
until ($condition->() || $attempts >= $total_attempts) {
1314
warn "Attempt $attempts" if DEBUG;
1415
$cb->();
15-
sleep 1;
16+
sleep .1;
1617
$attempts++;
1718
}
1819
$or->() if $or && !$condition->();

0 commit comments

Comments
 (0)