File Coverage

blib/lib/Evo/Promise/Sync.pm
Criterion Covered Total %
statement 34 34 100.0
branch 16 22 72.7
condition n/a
subroutine 5 5 100.0
pod 1 3 33.3
total 56 64 87.5


line stmt bran cond sub pod time code
1             package Evo::Promise::Sync;
2 12     12   5873 use Evo '-Class *';
  12         28  
  12         72  
3              
4             has 'promise', ro;
5             has $_, optional for qw(called v blocking should_resolve);
6              
7 16 50   16 0 119 sub reject ($self, $r) {
  16 50       48  
  16         33  
  16         37  
  16         30  
8 16 100       69 return if $self->called;
9 7         34 $self->called(1);
10 7 100       95 $self->blocking ? $self->promise->d_reject($r) : $self->promise->d_reject_continue($r);
11 7         36 $self;
12             }
13              
14 16 50   16 0 54 sub resolve ($self, $v) {
  16 50       50  
  16         34  
  16         31  
  16         31  
15 16 100       72 return if $self->called;
16 7         27 $self->called(1);
17 7 100       69 $self->blocking ? $self->should_resolve(1)->v($v) : $self->promise->d_resolve_continue($v);
18 7         21 $self;
19             }
20              
21 15 50   15 1 8797 sub try_thenable ($self, $thenable) {
  15 50       49  
  15         34  
  15         28  
  15         29  
22 15         60 $self->blocking(1);
23              
24             # reject drain second time, so don't bother checking "called"
25 15     15   86 my ($res, $rej) = (sub { $self->resolve(@_) }, sub { $self->reject(@_) });
  15         659  
  13         1589  
26 15 100       53 eval { $thenable->then($res, $rej); 1; } or $self->reject($@);
  15         56  
  13         108  
27 15         90 $self->blocking(0);
28             }
29              
30             1;
31              
32             __END__