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   5960 use Evo '-Class *';
  12         28  
  12         70  
3              
4             has 'promise', ro;
5             has $_, optional for qw(called v blocking should_resolve);
6              
7 16 50   16 0 109 sub reject ($self, $r) {
  16 50       43  
  16         24  
  16         25  
  16         24  
8 16 100       54 return if $self->called;
9 7         26 $self->called(1);
10 7 100       52 $self->blocking ? $self->promise->d_reject($r) : $self->promise->d_reject_continue($r);
11 7         26 $self;
12             }
13              
14 16 50   16 0 47 sub resolve ($self, $v) {
  16 50       39  
  16         24  
  16         27  
  16         23  
15 16 100       57 return if $self->called;
16 7         25 $self->called(1);
17 7 100       43 $self->blocking ? $self->should_resolve(1)->v($v) : $self->promise->d_resolve_continue($v);
18 7         17 $self;
19             }
20              
21 15 50   15 1 6273 sub try_thenable ($self, $thenable) {
  15 50       41  
  15         25  
  15         26  
  15         24  
22 15         45 $self->blocking(1);
23              
24             # reject drain second time, so don't bother checking "called"
25 15     15   73 my ($res, $rej) = (sub { $self->resolve(@_) }, sub { $self->reject(@_) });
  15         384  
  13         1051  
26 15 100       36 eval { $thenable->then($res, $rej); 1; } or $self->reject($@);
  15         58  
  13         84  
27 15         73 $self->blocking(0);
28             }
29              
30             1;
31              
32             __END__