File Coverage

blib/lib/Database/Async/Backoff/Exponential.pm
Criterion Covered Total %
statement 20 22 90.9
branch n/a
condition 0 6 0.0
subroutine 7 8 87.5
pod 0 2 0.0
total 27 38 71.0


line stmt bran cond sub pod time code
1             package Database::Async::Backoff::Exponential;
2              
3 6     6   267525 use strict;
  6         14  
  6         321  
4 6     6   36 use warnings;
  6         29  
  6         574  
5              
6             our $VERSION = '0.019'; # VERSION
7              
8 6     6   38 use parent qw(Database::Async::Backoff);
  6         12  
  6         53  
9              
10 6     6   1897 use mro qw(c3);
  6         1967  
  6         74  
11 6     6   320 use Future::AsyncAwait;
  6         14  
  6         66  
12 6     6   462 use List::Util qw(min);
  6         14  
  6         2153  
13              
14             Database::Async::Backoff->register(
15             exponential => __PACKAGE__
16             );
17              
18             sub new {
19 5     5 0 16 my ($class, %args) = @_;
20 5         27 return $class->next::method(
21             max_delay => 30,
22             initial_delay => 0.05,
23             %args
24             );
25             }
26              
27             sub next {
28 0     0 0   my ($self) = @_;
29             return $self->{delay} ||= min(
30             $self->max_delay,
31 0   0       (2 * ($self->{delay} // 0))
      0        
32             || $self->initial_delay
33             );
34             }
35              
36             1;